I’m putting this here, more as a reminder to myself, but also to perhaps help other people who want a simple no-frills guide to using Apache with mod_proxy to deal with your Tomcat content.
I wanted a URL like this from tomcat, http://myurl:8080/myapp to be http://myurl/myapp – nice and clean you see 🙂
The typical way to do this is to use Apache to handle all the http requests to http://myurl/myapp and to use a proxy to forward those requests to say http://myurl:8080/myapp – meanwhile all the user sees is the lovely clean URLs. I’ll give a brief account of how to do this here.
1. If you’re using the latest release of Apache (2), mod_proxy should be installed already. If not, do this:
- sudo apt-get install libapache2-mod-proxy-html
- apt-get install libxml2-dev
- add this to httpd.conf
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
- Restart Apache to ensure there are no issues.
2. In your Apache httpd.conf file, you need to add two lines for each application you wish to have mod_proxy handle.
ProxyPass /myapp http://myurl:8080/myapp
ProxyPassReverse /myapp http://myurl:8080/myapp
This is now telling Apache to forward any requests to myapp to Tomcat essentially which is listening on port 8080.
3. Next, you need to modify server.xml to tell Tomcat about the forwarding that’s going on. For that, you add the following.