Apache To Tomcat Setup Steps

Apache Tomcat J2EE Server

In below article we will discuss about the configurations required to connect apache to tomcat using mod_jk plugin.
mod_jk is a apache free library plugin to redirect the requests to tomcat connector port using mod-jk.conf and workers.properties. Please follow below steps to configure apache to tomcat communication.

1. Make sure mod_jk.so is available under modules directory of web server. If it is not there
download mod_jk-1.2.27-httpd-2.2.6.so and renamed as mod_jk.so
mv mod_jk-1.2.27-httpd-2.2.6.so mod_jk.so
Note: mod_jk-1.2.27-httpd-2.2.6.so is for Apache 2.2.6 and above
2. Create mod-jk.conf file under Apache conf directory

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/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
# Notes:
# 1) Changed from +ForwardURICompat.
# 2) For mod_rewrite compatibility, use +ForwardURIProxy (default since 1.2.24)
# See http://tomcat.apache.org/security-jk.html
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
# Mount your applications
#JkMount /__application__/* loadbalancer
JkMount /myApp/* 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 conf/uriworkermap.properties
# 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
# Note: Replaced JkShmFile logs/jk.shm due to SELinux issues. Refer to
# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=225452
JkShmFile run/jk.shm
DMZ Web Server Configuration Guide

# Add jkstatus for managing runtime data

JkMount status
Order deny,allow
Deny from all
Allow from

Note: needs to changed with the actual App server IP

3. Create workers. properties file under apache conf directory

# Define list of workers that will be used
# for mapping requests
# The configuration directives are valid
# for the mod_jk version 1.2.18 and later
# modify the host as your host IP or DNS name.
# Properties of worker1.
# Status worker for managing load balancer

Note: needs to changed with the actual App server IP
9007 tomcat connector port needs to be changed with the actual port number

4. Save all and restart Apache.

In case of any ┬ęCopyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply