Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 2.2 Virtual hosts + Tomcat 7 applications

I have installed on the same machine one apache server and one tomcat 7 server. The apache server is used and configured with virtual hosts enabled as is supposed to server multiple php websites. However, we have the need to serve some tomcat applications as well so we need to configure the ajp connector.

Everything goes well, I have succeeded in configuring multiple apache virtual hosts which serves tomcat apps but I have only one problem:

The session variables are not be maintained when accessing the java application through the apache virtual host. This works perfectly well when connecting directly to the 8080 port of the tomcat server.

I can see in the tomcat manager for each application the number of sessions is incremented with every refresh of a page from the apache virtual hosts.

The java application is deployed in tomcat in the /webapps/testapp folder.

The tomcat server xml has a ajp connector described as:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" 
maxThreads="300" minSpareThreads="10" enableLookups="false"
tcpNoDelay="true" tomcatAuthentication="false" URIEncoding="UTF-8" />

The apache webserver contains the virtual host:

<VirtualHost *:80>
    ServerName testapp.com
    ServerAlias *.testapp.com
    ProxyPreserveHost on
    ProxyRequests     off
    ProxyPass / ajp://localhost:8009/testapp/
    ProxyPassReverse / ajp://localhost:8009/testapp/
</VirtualHost>

So Apache proxy with tomcat is working fine. The thing is that jsp sessions are not working through the proxy. How can I make it work? Is it something wrong with my config?

like image 908
user2022901 Avatar asked Jan 29 '13 19:01

user2022901


1 Answers

So the solution is to add onother directive for the apache VHost:

ProxyPassReverseCookiePath /testapp /

This way the header of the cookies wil not be damaged and tomcat will see the session ok.

like image 136
user2022901 Avatar answered Oct 22 '22 16:10

user2022901