Setting up mod_jk with embedded Tomcat


Note: Replace ${JONAS_BASE} and ${APACHE_HOME} with appropriate values.

1. Open the file $JONAS_BASE/conf/server.xml and uncomment the following line:

 <!-- 
<Connector port="9009"
enableLookups="false" redirectPort="9043" debug="0"
protocol="AJP/1.3" />
-->

Edit it to look like the following:

<Connector port="9009"
enableLookups="false" redirectPort="9043" debug="0"
protocol="AJP/1.3" />

2. Now you can either let tomcat generate the mod_jk.conf file automatically,
    which will setup forwarding for a limited set of applications, or you can create a
    custom mod_jk.conf file.
    The automatically generated file cannot be customized since it is re-written every time
    tomcat is restarted by the user.
a) To enable automatic generation insert the following into the server.xml file nested under the base <Server> tag:
   <Listener className="org.apache.jk.config.ApacheConfig"
modJk="$APACHE_HOME/modules/mod_jk.so" />


    and insert the following under the <Host> element:
   <Listener className="org.apache.jk.config.ApacheConfig"
append="true" forwardAll="false"
modJk="$APACHE_HOME/modules/mod_jk.so"/>


    When jonas/tomcat is restarted, there will be a file created under $JONAS_BASE/conf/auto called mod_jk.conf.


b) If you want to create a custom file, the recommendation is to place mod_jk.conf under $JONAS_BASE/conf/jk.
    A simple mod_jk.conf file that can be used is:
   # Load the mod_jk module if not loaded.
<IfModule !mod_jk.c>
LoadModule jk_module "$APACHE_HOME/modules/mod_jk.so"
</IfModule>

# Specify location of worker file and log file. Worker file will follow shortly.
JkWorkersFile "$JONAS_BASE/conf/jk/workers.properties"
JkLogFile "$JONAS_BASE/logs/mod_jk.log"


# When and how much logging.
JkLogLevel emerg

# This is a little awkward. It seems mod_jk associates applications it will
# map to tomcat based on the virtual host. If for instance I wish to visit
# the jonasAdmin application through http://jonas-server/jonasAdmin from another
# machine and I have the following setting then the application behaves
# perfectly normally, i.e, struts kicks in as expected, form based
# authentication and forwarding is done exactly as one would expect if you
# were using the application directly using the appropriate port (9000).
# However, if you try using http://localhost/jonasAdmin from jonas-server
# without the explicit VirtualHost declaration, only the directory contents
# are mapped. So we need to explicitly mention both virtual hosts.
<VirtualHost jonas-server>
ServerName jonas-server
JkMount /olstore ajp13
JkMount /olstore/* ajp13
JkMount /jonasAdmin ajp13
JkMount /jonasAdmin/* ajp13
</VirtualHost>
# ajp13 is infact the worker name used in workers.properties.
<VirtualHost localhost>
ServerName localhost
JkMount /olstore ajp13
JkMount /olstore/* ajp13
JkMount /jonasAdmin ajp13
JkMount /jonasAdmin/* ajp13
</VirtualHost>

3. To tell apache to use this file, edit the $APACHE_HOME/conf/httpd.conf file and insert:

 Include ${JONAS_BASE}/conf/jk/mod_jk.conf
Note: Replace ${JONAS_BASE} with appropriate value.

4. Create a workers.properties file. This can be placed in

   $JONAS_ROOT/conf/jk/workers.properties

A sample that has been used successfully is:
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/usr/lib/jvm/java

#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and possibly something different elsewhere.
#
ps=/

#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#

#
#------ DEFAULT worket list ------------------------------------------
#---------------------------------------------------------------------
#
#
# The workers that your plugins should create and work with
#
# Add 'inprocess' if you want JNI connector
worker.list=ajp13
# , inprocess


#
#------ DEFAULT worker1 WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named worker1 and of type worker1
# Note that the name and the type do not have to match.
#
worker.ajp13.port=9009
worker.ajp13.host=jonas-server
worker.ajp13.type=ajp13


#----------------------------------------------------------

Once all this is completed, restart httpd and ensure that jonas/tomcat is up. You can follow that up with a quick test by visiting: http://host_name/jonasAdmin.
You should now be able to use the application as normal.