Thursday, March 22, 2012

Integrating apache tomact with mod_jk


This tutorial explains how to install and configure web-servers Apache or httpd 2 and tomcat 7 and integrate them with mod_jk or jk_module in Centos operating system. All the traffic to the apache will be redirected to tomcat.

We have one Centos 5.2 32 bit vmware instance
IP :
Hostname :

Installing Apache:
#yum install httpd*
yum install gcc gcc-cpp gcc-c++
Because you will need httpd-devel for apxs
yum install httpd-devel

Start the apache service
/etc/init.d/httpd start
#Chkconfig httpd on

[root@modjk bin]# netstat -ntplau | grep httpd
tcp        0      0 :::80                       :::*                        LISTEN      4948/httpd
[root@modjk bin]#

Installing Tomcat:
First install jdk

#rpm -ivh jdk-7u3-linux-i586.rpm
Set the following ernvironment variables:
export JAVA_HOME
export PATH
You can add it in /etc/profile for permanent use

Download Tomcat:

Untar the package:
tar xvzf apache-tomcat-7.0.26.tar.gz
cd apache-tomcat-7.0.26
cd bin

[root@modjk bin]# netstat -ntplau
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0       *                   LISTEN      4823/portmap
tcp        0      0 ::ffff:       :::*                        LISTEN      5251/java
tcp        0      0 :::8009                     :::*                        LISTEN      5251/java
tcp        0      0 :::8080                     :::*                        LISTEN      5251/java
[root@modjk bin]#

Now install jakarta connector:
tar xvzf jakarta-tomcat-connectors-1.2.15-src.tar.gz
cd jakarta-tomcat-connectors-1.2.15-src
cd jk/
cd native/
./configure --with-apxs=/usr/sbin/apxs
make install

Add the mod_jk module to httpd configuration file
vi /etc/httpd/conf/httpd.conf
LoadModule jk_module  modules/
Save the file.

Now retart the apache service
/etc/init.d/httpd restart

Check the mod_jk is loaded
#httpd -M

Create file
[root@modjk bin]# cat  /etc/httpd/conf.d/
[root@modjk bin]#

Create mod_jk.conf (apache conf file for mod_jk)
[root@modjk bin]# cat /etc/httpd/conf.d/mod_jk.conf
# Where to find
JkWorkersFile /etc/httpd/conf.d/
# Where to put jk logs
JkLogFile /var/log/httpd/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"
# Send servlet for context /examples to worker named worker1
JkMount /examples worker1
# Send JSPs for context /examples/* to worker named worker1
JkMount /examples/* worker1
[root@modjk bin]#

add the following line in /etc/httpd/conf/httpd.conf
Include /etc/httpd/conf.d/mod_jk.conf

Now restart the apache service
/etc/init.d/httpd restart - You will get apache default page - You will get tomcat default page - You will get tomcat examples page


  1. Hi

    i m getting error in apache..plz check it..

    [root@localhost conf.d]# /etc/init.d/httpd restart
    Stopping httpd: [FAILED]
    Starting httpd: Syntax error on line 2 of /etc/httpd/conf.d/mod_jk.conf:
    JkWorkersFile only allowed once

  2. You have declared JkWorkersFile more than once. May be you have declared it in httpd.conf and also in mod_jk.conf. Correct it and restart.

  3. I m getting a 500 Internal Server Error message.

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

  4. I have two jboss listening on port 8080, when I login it redirects to the same 8443, in front have an apache with mod_jk, but listening on port 8080 just in time to log in the browser it returns to port 8443 and gives jboss error in the access, I am one week trying to fix it and I can not.
    Sorry my english



Be nice. That's all.