I’ve recently re-configured my mail/file/web server and thought it to be a good time to give an Apache2 + Tomcat 5 setup a second try. The last time I tried doing this I couldn’t ever figure out the whole Apache vs. Apache2 vs. mod_jserv vs. mod_jk vs. mod_jk2 thing. The supporting documentation has gotten a little better (see Apache’s JK docs), but it’s still lacking in a few areas.
The big differences I found between mod_jk and mod_jk2 are that you no longer have to have the “Jk” directives like “JkWorkersFile”, “JkLogFile” in the httpd.conf Apache file. Instead, Apache just looks in the /etc/httpd/conf/ directory for the workers2.properties file that will define the connector workers. In this new workers2.properties is where you define which contexts are passed off to Tomcat.
After finding a few others’ experiences on the web (you have to love Experts-Exchange), it turns out it’s a lot simpler than I originally thought. I wanted to use the latest and greatest, so I’m using Apache2 (httpd) + Tomcat 5.0.24 on Fedora Core 1 with the mod_jk2 connector.
Getting all the pieces used to this puzzle used to be somewhat of a chore, especialy the jk connectors, but Apache has made it a lot easier now.
- Apache2 (use apt-get, preferrably)
- Tomcat 5
- JK 2 Connector
After installing Apache2 and Tomcat 5, here’s what needs to happen to get Apache to talk to Tomcat:
- Copy the “mod_jk2.so” module you downloaded as part of the JK 2 Connector into the apache modules directory (/usr/lib/httpd/modules/)
- Copy the “workers2.properties” file also of the JK 2 Connector into the apache conf directory (/etc/httpd/conf/)
- Edit the httpd.conf Apache configuration file in /etc/httpd/conf/ and add this LoadModule directive:
LoadModule jk2_module modules/mod_jk2.so
- Edit the /etc/httpd/conf/workers2.properties file to define which contexts you want Apache to hand off to Tomact. In my case, I have the “pebble” context that I want Tomcat to handle. This is what I added to the default workers2.properties file:
[uri:/pebble/*] group=lb ...
- The default Tomcat 5 server.xml file has the necessary ajp13 connector configuration, but just in case here is the Connector definition (a child element of the <Service> element):
<Connector className="org.apache.coyote.tomcat5.CoyoteConnector" port="8009" minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443" acceptCount="10" debug="0" connectionTimeout="0" useURIValidationHack="false" protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>
Restart httpd and tomcat and now when you go to http://localhost/tomcatContext, you should see your Tomcat context, served up through Apache!
