Monday, February 15, 2010

mod_jk [Configuring mod_jk for Apache]

1. Visit the following url for downloading:

http://tomcat.apache.org/download-connectors.cgi

2. Change the current directory

cd /usr/local/

3. Unzip/untar the file

tar -zxvf ./tomcat-connectors-1.2.28-src.tar.gz

4. Configure/Build mod_jk

cd tomcat-connectors-1.2.28-src

cd native

./configure --with-apxs=/usr/local/apache/bin/apxs --enable-EAPI

cp ./root/modules/mod_jk.so $APACHE_HOME/libexec

5. Create workers.properties in $APACHE_HOME/conf/jk with the following contents:

workers.tomcat_home=$CATALINA_HOME
workers.java_home=$JAVA_HOME
ps=/
worker.list=worker0

worker.worker0.port=8009
worker.worker0.host=localhost
worker.worker0.type=ajp13
worker.worker0.lbfactor=1

6. For Apache 1.3.x, edit $APACHE_HOME/conf/httpd.conf and add the following to the LoadModules section:

LoadModule jk_module libexec/mod_jk.so

7. For Apache 2.0.x, edit $APACHE_HOME/conf/httpd.conf and add the following to the LoadModules section:

LoadModule jk_module modules/mod_jk.so

8. Edit $APACHE_HOME/conf/httpd.conf and add the following to the AddModules section (if you have it - Apache 2 and later versions of Apache 1.3.x don't):

AddModule mod_jk.c

9. Edit $APACHE_HOME/conf/httpd.conf and add the following before Section 3 in httpd.conf:

#
# Mod_jk settings
#

JkWorkersFile "conf/workers.properties"
JkLogFile "logs/mod_jk.log"

JkLogLevel error

JkMount /examples/jsp default
JkMount /examples/jsp/* default

# End of mod_jk settings

The location of the Jk workers.properties and log files are relative to $APACHE_HOME. If you prefer other locations, make sure you fully qualify the paths.

In this test, we are directing all URIs that begin with "/examples/jsp" to Tomcat. The name "worker0" corresponds to the JK worker that we defined in $APACHE_HOME/conf/workers.properties. We define two JK Mounts in order to match the URI of "/examples/jsp" as well as any that start with "/examples/jsp". In a real world situation, we might only direct JSPs or servlets to the JK worker.

10. Find the line in $APACHE_HOME/httpd.conf that starts with "Port" - make sure you have it pointing to a port that is not in use. Lately, Apache has been coming with the "Port" directive set to "8080", which is the same port that Tomcat will listen on. If you don't have any other web server running, you can set it to "80" instead.

11. Test httpd.conf by typing the following:

cd $APACHE_HOME/bin
apachectl configtest

No comments:

Post a Comment