Install mod_jk

Use mod_jk to bridge apache and Jboss

mod_jk is an apache extension that you can use to redirect incoming http requests to an application server. It lets you configure multiple applications servers by virtual host urls, and provides a means of setting up load balancing preferences between application servers. It’s very useful because it lets apache do what it does best – serve up http requests. Well, its good at serving up html too but apache will usually do a much better job of handling load balancing that most application servers. Let the web server handle http, and let the application server handle the business logic number crunching.

mod_jk 1.2.x is supposedly better than 2.0. Why? Ok, now that I understand why, on with installing mod_jk 1.2.x

Build/Install mod_jk

To start, make sure apache and mod_jk are installed. you can use the yum installer to make sure you have apache 2 installed. you might need to also make sure you have the http-devel package installed if you are going to build mod_jk binaries.

[root@bedrock native]# yum install httpd-devel

This should install the current version of apache. We’re going to also have to download the connectors and build them since there are no binary distributions available for fedora. Download the source code here.

Once its downloaded, untar and gunzip the file:

[root@bedrock native]# tar -zxvf tomcat-connectors-1.2.28-src.tar.gz

cd into the uncompressed folder, and compile the package

[root@bedrock native]# cd native
[root@bedrock native]# ./configure –with-apxs=/usr/sbin/apxs (or where ever the apxs/apxs2 is)
[root@bedrock native]# make
[root@bedrock native]# make install

Configure mod_jk

Now that it’s built, we can set up apache to use mod_jk. We’ll need to add/modify the mod-jk.conf file first:

[root@bedrock conf]# vi /etc/httpd/conf.d/mod-jk.conf

You an get the full text file from the jboss wiki. Normally, declarations like these go in the http.conf file, but apache these days has a felxible configuration architecture that allows you to break up configuration as long as its listed in the “/etc/httpd/conf.d/” directory. If you have that mod-jk.conf file in there, you’ll want to edit this mod-jk.conf file in order to configure the exact way you want mod_jk to handle your hosts/ip/port setup.

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

# Where to find
JkWorkersFile conf/

<Location /jkstatus>
	JkMount status
	Order deny,allow
	#Deny from all
	Allow from

# for virtual hosts, specify the alias by ip

# and map them to domains to listen for
# the JKAutoAlias maps an alias you can map in

	JkMount               /* myapp1
	JkAutoAlias           /myapp1


	JkMount               /* myapp2
	kAutoAlias           /myapp2

You will also want to configure your workers and uriworkermap property files:

[root@bedrock conf]# vi /etc/httpd/conf.d/

# Define the list of workers that will be used

# Define myapp1
# modify the host as your host IP or DNS name.
# more info here:
worker.myapp1.prepost_timeout=10000 #Not required if using ping_mode=A
worker.myapp1.connect_timeout=10000 #Not required if using ping_mode=A
worker.myapp1.ping_mode=A #As of mod_jk 1.2.27

# Define myapp2
# modify the host as your host IP or DNS name.
worker.myapp2.prepost_timeout=10000 #Not required if using ping_mode=A
worker.myapp2.connect_timeout=10000 #Not required if using ping_mode=A
worker.myapp2.ping_mode=A #As of mod_jk 1.2.27

You will want to fine tune this to your particular setup. The full connector property reference can be found on the apache connectors website.

Next you’ll want to map the host contexts for your particular configuration. Remember the JKAutoAlias we configured earlier in the VirtualHost config? We’ll want to map those virtual aliases to actual contexts, and worker nodes in

# Simple config
# Mount the Servlet context to the ajp13 worker



In this notation we have to add each context twice, one to map the root of the context, and a second one to map everything underneath – that’s what the * at the end of the second mapping refers to.

Don’t forget that you can debug the mod_jk setup by tailing the apache logs:

[root@bedrock conf.d]# tail -500 /var/log/httpd/mod_jk.log


[root@bedrock conf.d]# tail -500 /var/log/httpd/error.log

Complete files

Download Tomcat-Apache Mod_jk connectors
how to untar/build mod_jk src distributions
documentation on how to configure mod_jk to work with jboss
the Apache connector property reference guid
the apache reference guide

Comments (0)

› No comments yet.

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pingbacks (1)