Using the mod_jk connector is an alternative but more complex method of integrating Tomcat and Apache together. The concept behind this method is to have Apache serve the static content of the website, and Tomcat to serve the Java related content. This could be a better alternative if your website contains mostly HTML pages.
The mod_jk connector along with mod_proxy_ajp are the only recommend methods of Tomcat and Apache integration. mod_jk is still actively under development, and is very stable for production servers, as well it supports both Apache 1.3, and 2.x. Other past alternatives like mod_webapp, mod_jserv, mod_jk2 are not longer supported and are consider deprecated.
mod_jk Package Issue for Ubuntu
For Ubuntu 7.04 there is an error in the mod_jk package. It currently has two packages for mod_jk:
libapache-mod-jk which depends on apache
libapache2-mod-jk2 which depends on apache2
As mention previously, mod_jk2 is already deprecated and mod_jk works for both Apache 1.3, and 2.x.
To properly configure Tomcat and Apache to use mod_jk the connector must be manually, build and set up from the source.
Installing and Configuring mod_jk
Download and extract the latest connector from the Tomcat website http://tomcat.apache.org/download-connectors.cgi, then configure and build it:
$ cd tomcat-connectors-1.2.23-src/native
$ ./buildconf.sh
$ ./configure --with-apxs=/usr/bin/apxs2
$ make; make install
Verify the mod_jk.so module exist in the apache module directory /usr/lib/apache2/module.
Note: The programs are required to configure and build the connector: automake, autoconf, libtoolize, and apxs2. To obtain these programs install the following packages in Ubuntu: libtool, automake, and apache2-threaded-dev
libtool error when compiling
On some systems the 'make' command will fail with the following error:
libtool: compile: unable to infer tagged configuration
libtool: compile: specify a tag with `--tag'
This is due to libtool not using the correct gcc when compiling. A workaround would be to add the parameter '--tag CXX' inside the Makefile.
$ cd tomcat-connectors-1.2.23-src/native/common
$ nano Makefile
Inside the Makefile the change line from:
LIBTOOL = /usr/share/apr-1.0/build/libtool --silent
to:
LIBTOOL = /usr/share/apr-1.0/build/libtool --silent --tag CXX
Creating the workers.properties
Create a workers.properties file in the Apache configuration directory and add the following lines to it.
$ nano /etc/apache2/workers.properties
# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
workers.tomcat_home=/usr/share/tomcat5.5
workers.java_home=/usr/lib/java-1.5.0-sun
ps=/
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1
Configure Apache for mod_jk
Create the jk module configuration files for Apache
$ nano /etc/apache2/mods-available/jk.load
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
$ nano /etc/apache2/mods-available/jk.conf
<IfModule mod_jk.c>
# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Globally deny access to the WEB-INF directory
<LocationMatch '.*WEB-INF.*' >
Order deny,allow
Deny from all
</LocationMatch>
</IfModule>
After creating the configuration files you can now enable the jk module for Apache
$ a2enmod jk
Sending JSP and Servlets through mod_jk
Inside the virtual host you can mount JSP and Servlet context to the worker define in the workers.properties file. For example to mount the JSP and Servlet examples from Tomcat add the following lines:
JkMount /jsp-examples/*.jsp worker1
JkMount /servlets-examples/servlet/* worker1
Apache DirectoryIndex
If your website uses index.jsp it must be download inside the DirectoryIndex of Apache. Modified the file /etc/apache2/mods-enabled/dir.conf and add index.jsp to the list.