I've built a setup with Apache HTTP and Tomcat, which communicate to each other via mod_proxy. I've pasted the configuration I use below. The problem I experience is session loss and I think this has to do with improper proxy configuration. I read lots of articles but still can't figure out what I'm doing wrong.
httpd.conf:
<VirtualHost MACHINE_IP:80>
ServerName www.mydomain.com
ProxyRequests Off
ProxyPass /apps/my_app http://MACHINE_IP:8080/my_app
ProxyPassReverse /apps/my_app http://MACHINE_IP:8080/my_app
Header set P3P "CP=\"HONK\""
</VirtualHost>
<VirtualHost MACHINE_IP:443>
ServerName www.mydomain.com
ProxyRequests Off
ProxyPass /apps/my_app https://MACHINE_IP:8443/my_app
ProxyPassReverse /apps/my_app https://MACHINE_IP:8443/my_app
Header set P3P "CP=\"HONK\""
</VirtualHost>
Tomcat (on MACHINE_IP) runs on usual ports 8080 and 8843 and is configured as follows (I think this is the default configuration):
<Server port="8005" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
/>
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="cert/tomcat.keystore"
keystorePass="password"
/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
</Service>
</Server>
Strange thing is that when I configure any proxyName and proxyPort in server.xml, and also domain name to the Host, everything stops working. The above sample of server.xml is working, but for some reason there is a session loss.
You are seeing session loss because you have changed the context path for the application with
ProxyPass /apps/my_app https://MACHINE_IP:8443/my_app
from /apps/my_app
in httpd to /my_app
in Tomcat. That measn Tomcat will issue sessions cookies for the path /my_app
which doesn;t match what the client is requesting form httpd.
To fix this use ProxyPassReverseCookiePath