Recently I had to install a Java application for a client using Tomcat6. The application needed to run from the root of their domain so I also installed apache2 and mod_proxy_ajp to set up a proxy to make this work. After a bit of massaging and googling to deal with Location Headers including the original path of the servlets rather than the proxy root. I've come up with this.
<VirtualHost *:80>
ServerName myclientssite.com
ErrorLog /var/log/apache2/ajp.error.log
CustomLog /var/log/apache2/ajp.log combined
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPass / ajp://localhost:8009/appname/
ProxyPassReverse / http://localhost:8080/appname/
ProxyPassReverseCookiePath /appname/ /
Header edit Location ^([^/]*//[^/]*)?/appname/(.*)$ $1/$2
</VirtualHost>
My question is wither this is the the best solution. It seems with out mod_headers and the Header edit line and headers will usually include the appname subdirectory.
Is the Java application building its Location
headers from the information in the request (rather than from some explicit configuration)? In this case, it should get the location right if you use ProxyPreserveHost On
.
The case where you'd need the to change the header is if your Apache Httpd frontend is over HTTPS and the connection from Apache Httpd to the Java container is over plain HTTP or AJP. Not that, in theory (and that might not always be the case in practice), the Location header requires an absolute URI, so you might not need such a complex expression if you already know the hostname.
I'd also suggest using an HTTP reverse proxy rather than AJP (it's quite similar in the end, but it seems to have more support).
ProxyRequests Off
ProxyPass /appname/ http://localhost:8080/appname/
ProxyPassReverse /appname/ http://localhost:8080/appname/
ProxyPreserveHost On
# If you're using HTTPS
Header edit Location ^http://www.example/appname/ https://www.example/appname/