Tuesday, July 3, 2007

Tomcat 5.5 with Apache 2.0 Integration in 5 Simple Steps

The simplest configuration is described. It assumes you already have Tomcat 5.5 and Apache 2.0 (instructions for Apache 1.3 is also provided) installed and running.
The instructions are applicable (have been tested) for Windows as well as Linux platform.

Assume you want to map test directory of Apache to the mytest web application of Tomcat. Change the name appropriately to suit your configuration.

1. Shutdown Apache & Tomcat Server

2. Add the following lines to httpd.conf (in conf directory of Apache base directory)

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyPass /test/ http://localhost:8081/mytest/
ProxyPassReverse /test/ http://localhost:8081/mytest/

Note: Replace localhost with the appropriate IP address or hostname of the server where Tomcat is installed.

Note 2: On older Apache 1.3 you will have to use libproxy.so instead:

LoadModule proxy_module modules/libproxy.so
AddModule mod_proxy.c

3. Add to Server.xml (in conf directory of Tomcat base directory)

Note: Change the proxyName to the server name served by Apache. For example if you want to access the application at http://www.example.com/test/, then proxyName should be www.example.com.

4. Restart Tomcat Server and then Apache Server

5. Test the URL.

6. Have a cup of Java and relax.
BTW: That’s not actually a required step, but what the heck.

You are done!

Note: This is the simplest way to integrate the two servers. However in this configuration the static pages are also served by Tomcat. This is not so bad with the recent performance improvements in Tomcat 5.5. If you still want Apache to serve your static pages then welcome to jk connector hell.