Proxying Tomcat Behind Apache Web-server [Linux]

The contents of this post might come through as much too simple to merit a post, however, the information contained herein benefited me greatly. And before I might forget the small details, as is the case with most of the configuration tasks, I think it’s best for me to jot down these notes.

Another reason why this task turned out to be strangely convoluted and unyielding to me was the fact that I had embarked to do this adopting an approach used to cluster Tomcats behind Apache web-server in a typical load-balancing setup. This approach, if anyone is curious enough to understand, is explained in great detail as part of Tomcat’s official documentation here. While we’re on it, I must add that the official documentation on clustering Tomcat’s is really very well written.

So coming to the task at hand, I was simply trying to proxy a Tomcat application behind an Apache web-server. The OS I was working on was Ubuntu 10.04. However, I think the information contained here is applicable to almost any Linux distribution.

The first task to get this working is to enable mod_proxy on your Apache web-server.

mac-x:/etc/apache2$ sudo a2enmod proxy_http
Enabling proxy as a dependency Module proxy installed;
run /etc/init.d/apache2 force-reload to enable. Module proxy_http installed;
run /etc/init.d/apache2 force-reload to enable.

Once you’re done with this, you need to add a proxy config script for Apache to know how to map inbound URLs to the local URLs served by the Tomcat:

mac-x:/etc/apache2/sites-available$ sudo vim tomcat-app_proxy

Add the following to the file:

<Proxy *>
   Order deny,allow
   Allow from all
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /app-context http://localhost:port/app-context
ProxyPassReverse /app-context http://localhost:port/app-context

Replace the app-context and port with applicable values in your case.

Once you’re done with this, you’ll need to enable this proxy site for Apache. To do so, execute the following commands from within the sites-available folder:

mac-x:/etc/apache2/sites-available$ a2ensite jira-mod_proxy
Site jira-mod_proxy installed; run /etc/init.d/apache2 reload to enable.
mac-x:/etc/apache2/sites-available$ /etc/init.d/apache2 reload
Reloading apache 2.0 configuration....

And with that, you can go ahead and verify that your Tomcat application is now accessible on http://localhost/app-context.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s