How do I connect Apache to Tomcat using the mod_jk module?
Author: Deron Eriksson
Description: This tutorial describes how to connect the Apache Web Server to Tomcat using the mod_jk module.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.4 || Tomcat 5.5.20 || Apache HTTP Server 2.2.4
(Continued from page 1)
After that, I modified httpd.conf by adding the following code for mod_jk. We load the mod_jk module that we placed in the modules directory using the LoadModule directive. We mount the tomcat-demo web project that we have running in EclipseSW.
httpd.conf mod_jk modification
LoadModule jk_module modules/mod_jk-apache-2.2.4.so <IfModule jk_module> JkWorkersFile conf/workers.properties JkLogFile logs/mod_jk.log JkLogStampFormat "[%b %d %Y - %H:%M:%S] " JkRequestLogFormat "%w %V %T" JkLogLevel info JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories Alias /tomcat-demo "C:/projects/workspace/tomcat-demo/" <Directory "C:/projects/workspace/tomcat-demo/"> AllowOverride None Allow from all </Directory> <Location /*/WEB-INF/*> deny from all </Location> JkMount /tomcat-demo/* myworker </IfModule>
We can verify the syntax of these modifications via:
C:\Apache2.2.4\bin>httpd.exe -t Syntax OK C:\Apache2.2.4\bin>
Since that worked, let's now try hitting the 'tomcat-demo' test servletW running on Tomcat through Apache via the mod_jk connector. We can do this by hitting http://localhost/tomcat-demo/test:
As you can see, it works! This has been a demonstration of how you can have Apache connect to Tomcat via mod_jk when you have both running locally on your machine. If you're developing software locally running Tomcat in Eclipse, why would you ever want to hit your web application through Apache connecting to Tomcat? Well, production environment typically have web servers sitting in front of your servlet containers, and sometimes complicated issues can arise in these situations. By setting up Apache locally in front of your local Tomcat, it can help you mimic your production environment, which can aid in debugging.