Session Expired on tomcat8 behind apache2 ProxyPass - apache

For a web application named whys written with VAADIN 7.3.8, i deployed a tomcat8 server behind an apache one (and redirected app.whys.fr to whys.fr:8080/Whys wich is my app location).
When i go on http://whys.fr:8080/Whys, everything looks good, but when i go on http://app.whys.fr, i get a session expired message immediatly, and no logs to tell me why (nothing in catalina.out).
You can test it by your own to see the difference ;).
Here is my proxy configuration :
<VirtualHost *:80>
ServerName app.whys.fr
ProxyRequests On
ProxyPass / http://localhost:8080/Whys/
ProxyPassReverse / http://localhost:8080/Whys/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
<VirtualHost *:80>
ServerName whys.fr
</VirtualHost>
and my tomcat Connector in server.xml:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
apache2 has mod_proxy,mod_proxy_http and mod_proxy_connect enabled, timeout for session in web.xml is 30 mins.
EDIT: forgot to mention: my application is using #Push (vaadin feature)

The problem was with vaadin's Push.
With push activated, you need to redirect the cookies throught proxy too, in order to keep your session alive, else, it is instantly invalidated.
so here is how to do with a vaadin push application behind apache2 proxy :
<VirtualHost *:80>
ServerName yourdomain.tld
ProxyRequests On
ProxyPass / http://localhost:8080/yourApplication/
ProxyPassReverse / http://localhost:8080/yourApplication/
ProxyPassReverseCookiePath /yourApplication /
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>

Related

apache2 proxy redirect configuration

This has been asked a bunch of time I realize but I still can't seem to get it working. Here is my situation. I have 2 servers on my network. Server A is public facing which hosts my website. My second server also has apache running with a web application which I would like to access externally. I am not exactly sure how to configure this. My current config looks like this
NameVirtualHost *:2323
<VirtualHost *:2323>
ProxyPass / http://192.168.1.7/ampache
ProxyPassReverse / http://192.168.1.7/ampache
servername slave-1
ProxyPreserveHost On
ProxyRequests Off
</VirtualHost>
So I would like all traffic on https://my_domain.xx:2323 to redirect to 192.168.1.7/ampache
Thank you
I fixed it by doing the following
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass /airsonic http://192.168.1.7:8088/airsonic
ProxyPassReverse /airsonic http://192.168.1.7:8088/airsonic

remove 8080 port from tomcat url

I am using httpd and tomcat for my web application,
so i want to remove 8080 port which is coming in my url.
i tried following things
Made <Connector port="80" in server.xml but its not working.
Used Proxypass in httpd.conf
<VirtualHost *:80>
ServerName myapp.com
ServerAlias www.myapp.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /MyAppPath http://localhost:8080
ProxyPassReverse http://localhost:8080
but both of the things are not working.
whenever i am hitting www.mysite.com its showing apache 2.2 page.
To reach out to mysite every time i need to put www.mysite.com:8080/
please guide.
Thanks in Advance
Resolved by pointing tomcat to 80 and stoped the httpd service.
Worked for me.

Redirect apache to tomcat

I am trying to redirect domain.com to tomcat7, I tried a lot of configurations and doesnt seem to work...
This is my /etc/tomcat7/server.xml config
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443"
proxyName="domain.com"
proxyPort="80"
/>
And this is my /etc/apache2/httpd.conf
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
AddModule mod_proxy.c
ProxyPass / http://domain.com:8080/
ProxyPassReverse / http://domain.com:8080/
<Location "/">
Order allow,deny
Allow from all
</Location>
When i go to domain.com i get this default apache message:
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
When i go to domain.com:8080 i get the tomcat message:
It works !
If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!
This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat7/webapps/ROOT/index.html
I loaded few .WAR with tomcat assistant one is called App1.
If i go to domain.com/App1 i get:
The requested URL /App1/ was not found on this server.
But if i use domain.com:8080/App1 the app works properly and shows a for loop for example.
UPDATE: tried /etc/apache2/ports.conf with this config:
Listen 80
ServerName domain.com
DocumentRoot /var/www/domain.com/public_html
NameVirtualHost IP
UPDATE2: i just wiped out my debian and i just used /etc/apache2/httpd.conf to set this: (only with this file I achieved same result as above, still must use domain.com:8080/appname to run an app...)
<VirtualHost *:8080>
ProxyRequests off
ProxyPreserveHost on
ServerName domain.com
ServerAlias *.domain.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
How can I do it to redirect straight to tomcat default message instead of apaches ?
And how to get rid of that :8080 and make apps work on domain.com/appname
After long time this is tha answer:
Edit file: /etc/apache2/sites-available/default
ServerAdmin webmaster#localhost
ServerName domain.com
DocumentRoot /var/www
ProxyPreserveHost on
ProxyRequests off
ProxyPass /phpmyadmin !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
using ! to prevent forwarding phpadmin to tomcat

Apache + proxy + tomcat: error - duplicated app name

I have configured an apache 2.2 server to forward requests to a tomcat 6 application listen on 8080/tcp. When the request is processed by apache, it duplicates the name of the application. So an error is posted on the browser.
Apache and tomcat are living at the same server, behind a firewall. On the firewall, I have created a redirect rule to forward all 80/tcp requisitions to apacheĀ“s server. 8080 tcp port is blocked on firewall.
Here is my apache 2.2 config:
<VirtualHost *:80>
ServerName myaddress.com
ServerAlias myaddress.com
ServerAdmin webmaster#myaddress.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
Order allow,deny
Allow from all
ProxyPass http://localhost:8080/portal
ProxyPassReverse http://localhost:8080/portal
</Location>
</VirtualHost>
Here is my server.xml config:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" proxyPort="80" proxyName="myaddress.com"/>
When I type http://myaddress.com in the browser, the address is replaced by http://myaddress.com/portal and the following error message is showed:
HTTP Status 404 - /portalportal/
type Status report
message /portalportal/
description The requested resource (/portalportal/) is not available.
It should look like:
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
the "/" means it should be accessed from http://localhost -> proxied to -> http://localhost:8080/portal.
Instead of this you can connect tomcat to apache using workers so that you never have to deal with port 8080, only the apache ones. A good source is http://www3.ntu.edu.sg/home/ehchua/programming/howto/ApachePlusTomcat_HowTo.html
and there are many more guides you can find. So you will have JKmount with the desired path along with your worker name
JkMount /path worker1 for example
Hope I didn't misunderstand your question, and hope it helps!

Apache + Tomcat: Using mod_proxy instead of AJP

Is there any way I connect Apache to Tomcat using an HTTP proxy such that Tomcat gets the correct incoming host name rather than localhost? I'm using this directive in apache:
ProxyPass /path http://localhost:8080/path
But it comes through as localhost, which is useless when we have a bunch of sites on the same server. I could set the host manually in the server config:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyName="pretend.host" proxyPort="80" />
But that again doesn't serve more than one site. And I don't like the idea of using a different internal port for each site, that sounds really ugly.
Is there no way to transfer the port when I proxy it?
(If you ask why I don't just use AJP, the answer is this error. I'm trying everything I can before giving up on Tomcat and Apache entirely)
The settings you are looking for are:
<VirtualHost *:80>
ServerName public.server.name
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Note that we're using localhost as the proxy target. We can do this since we enable ProxyPreserveHost. The documentation states that
It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated by the backend server.
which sounds exactly like what you are doing.
I think your best bet if you want multiple sites on the same server is to use virtual hosts in your Apache configuration. Here's an example:
<VirtualHost *:80>
ServerName server.domain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://server.domain.com:8080/
ProxyPassReverse / http://server.domain.com:8080/
<Location />
Order allow,deny
Allow from all
</Location>
As long as you have server.domain.com registered in your external DNS, the incoming host name will be displayed in client URLs. I'm running a single server hosting 6 separate sites, including 3 that are back by Tomcat, using this method.
You can still use AJP, and you should since it's faster than HTTP. Just make sure to enable it in http.conf:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
In that case, this configuration works for me:
<VirtualHost *:80>
ServerName public.server.name
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8080/
# ProxyPassReverse might not be needed,
# it's only for redirecting from inside.
# ProxyPassReverse / ajp://localhost:8080/
</VirtualHost>