Saturday, December 24, 2005

Using mod_jk 1.2.x with JBoss/Tomcat bundle and Apache2 with Suse 10

Originally used source is located at:

This article has some specifics related to SuSe 10:

Using Mod_jk1.2 With JBoss

Quick Overview

  1. Download Apache2

  2. Download modjk 1.2.x

  3. Change the main Apache config to include modjk config

  4. Create the modjk config

  5. Configure the modjk workers (which JBoss/Tomcat nodes Apache uses)

  6. Configure the Apache URIs served by modjk (the applications served by JBoss/Tomcat)

  7. Restart Apache

  8. Configure Tomcat (Give each JBoss/Tomcat a jvmRoute for session stickness)

  9. Restart JBoss

  10. Test it

Step #1: Download Apache2 Web Server
Get the latest Apache2 package from and install it. We require no special configuration, just use the default settings. In the following steps, APACHE_HOME will represent the Apache install directory.

Best to do with SuSe is using yast2 or apt:
apt install apache2

Step #2: Download mod_jk 1.2.x
Download the latest package available from Jakarta's 'Tomcat connector section' page . Always download the latest release if possible.
Rename the lib and drop it in /usr/lib/apache2 directory (see comments below).

Yast and apt have (at the moment of writing this) too old version of mod_jk. So I had to build from source (binary versions were available only for x64).
There are some specifics:
To build from source you need to apxs installed. To have that you need to install apache2-devel package: apt install apache2-devel

Then build from native dir:
./configure --with-apxs=/usr/sbin/apxs2 --enable-jni

"/usr/sbin/apxs2" is vere you will get apxs2 installed on SuSe 10 and it is not a standard location for mod_jk.


make install
(If you do make install the lib will be copied automatically to the right location)

Step #3: Setup Apache to use modjk
Add this line at the very bottom in APACHE_HOME/httpd.conf :

# Include mod_jk configuration file
Include /etc/apache2/mod_jk.conf

Step #4: Create the modjk config
Under APACHE_HOME/conf, create mod_jk.conf and populate it as follows:

This config file has all the paths changed for SuSe 10

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module usr/lib/apache2/

# Where to find
JkWorkersFile /etc/apache2/

# 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 indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Mount your applications
JkMount /application/* loadbalancer

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile /etc/apache2/

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile /var/log/apache2/jk.shm

# Add jkstatus for managing runtime data
<Location /jkstatus/>
JkMount status
Order deny,allow
Deny from all
Allow from

mod_jk is ready to forward requests to JBoss instances. We need now to setup the workers

Step #5: Configuring workers
Under APACHE_HOME, create and populate it as follows:

# Define list of workers that will be used
# for mapping requests

# Define Node1
# modify the host as your host IP or DNS name.
#worker.node1.local_worker=1 (1)

# Define Node2
# modify the host as your host IP or DNS name.
#worker.node2.local_worker=1 (1)

# Load-balancing behaviour

# Status worker for managing load balancer

You have to change the host names for yourself.

Step #6: Create the URI to worker map file
Create a file in the APACHE_HOME directory. This file should contain the URL mappings you want Apache to forward to Tomcat. The format of the file is /url=worker_name. To get things started, paste this example into the file you created:

# Simple worker configuration file

# Mount the Servlet context to the ajp13 worker

This will configure mod_jk to forward requests to /jmx-console and /web-console to Tomcat.

Step #7: Restart Apache

Step #8: Configure Tomcat
To complete the configuration, we also need to name each node accordingly to the names specified in
Edit JBOSS_HOME/server/all/deploy/jbossweb-tomcat50.sar/server.xml (replace /all with your own server name, also tomcat version may change with later versions of JBoss)
Locate the <Engine….> element and add an attribute jvmRoute:

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">

The jvmRoute attribute must match the name specified in

Finally, we need to tell Tomcat to add the jvmRoute value to its session cookies so that mod_jk can route incoming requests.
Edit JBOSS_HOME/server/all/deploy/jbossweb-tomcat50.sar/META-INF/jboss-service.xml (replace /all with your own server name)
Locate the <attribute> element with a name of UseJK, and set its value to "true":

<attribute name="UseJK">true</attribute>

Step #9: Restart JBoss AS.

Step #10: Access the JBoss AS web-console through Apache by browsing to http://localhost/web-console or http://localhost/jmx-console (depends what you have configured/installed) and you should see the JBoss web console page.

1 comment:

blogger999 said...

Thanks for such good post.

My question is about:
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

Does %T log the time taken to process each request at JBoss- i.e., time since a request leave the Apache server until a corresponding response is sent back?