Access a local Tomcat through Apache

Heard a nice ‘trick’ some time ago I need to write about (so I do not forget it ;-).

I wanted to access a tomcat web application on a server that was mainly running a Drupal CMS.

As I do not like shooting holes in firewalls I dislike the use of port 8080 too. The solution I heard was both simple and elegant.

Basically one installs and configures a Tomcat server and deploy a web application on this Tomcat server listening top a port that can only be reached on the server itself (8081 in the example below).

In the Apache ‘httpd.conf’ file you enable mod_proxy by uncommenting the line:

   1: LoadModule proxy_module modules/

Then you define a mapping of the tomcat URL to a URL inside the apache servers web space.


   2: # http://<ip>:8081//?">http://<ip>:8081/<Webapp>/<Webappurl>?<parameters>

   3: # is mapped mapped to: 

   4: # http://<ip>/<Webappurl>?<parameters> 


   6: ProxyPass /OAIHandler

   7: ProxyPassReverse /OAIHandler

In above example:

  • 8081 is the local port to the Tomcat server, not reachable from the outside.
  • is the local address of the server, not reachable from the outside.
  • OAIHandler is a URL inside the web application that does the work (and I re-used it as URL inside the Drupal webspace). URL parameters are nicely appended.
  • LiLiTarget is the name of the web application inside Tomcat’s ‘webapps’ directory.
  • The name of the web application is not used as part of the URL.

Nice side effect of this approach is that you easily swap Tomcat servers or have multiple Tomcat servers running, each with their own port number and each running only a single webapp deployed. This way you can nicely restart/maintain a single Tomcat without affecting the reset of the instances or have multiple Tomcat versions running on a single server.

This entry was posted in Tomcat. Bookmark the permalink.

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