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:
Then you define a mapping of the tomcat URL to a URL inside the apache servers web space.
In above example:
- 8081 is the local port to the Tomcat server, not reachable from the outside.
- 127.0.0.1 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.