Version 32

                           Using mod_jk with JBoss



                    WARNING: DO NOT USE THIS WIKI PAGE!!!

       Apache Tomcat and JBoss recommend using mod_jk1.2.x connectors only. Both mod_jk and mod_jk2 are deprecated, unsupported and no further developments are going on in the community

    Please use this other wiki instead: UsingMod_jk1.2WithJBoss.







    Note: Soon, the functionality provided by mod_jk1.2 will be replaced by a new module, mod_proxy_ajp, that will be included in Apache 2.1. *




    There are relatively few differences between the non-integrated stock Tomcat that you download from Tomcat. The main differences are that it has been made into an MBean and placed in an exploded archive SAR; it is also integrated with JBossSX security via some custom valves and the such; and it has been integrated with JBoss's deployers/classloaders. You will find the standard server.xml embedded in the server/xxx/deploy/jbossweb-tomcat41.sar/META-INF/jboss-service.xml or for JBoss 3.2.4 and later in the



    Integrating with mod_jk2


    The author recommends that you use mod_jk2, and not mod_jk. mod_jk2 is a much more robust and performant implementation, and it works both with Apache 1.3 and Apache 2.0.



    NOTE: This wiki page is old. Current recommendation from Apache Tomcat team and JBoss is that you should use mod_jk1.2 connectors only.





    1) First step : install Apache.



    This should be pretty straigthforward. Apache is available at We recommend that you take the latest version of Apache 2. For the rest of this document, APACHE_HOME will represent your apache install directory.





    2) Second step : configure Apache to serve your static content.



    Apache can be used to serve your static content (images, css, javascript files) faster than JBoss. As an example, if you store your static content in c:\static, add those lines to APACHE_HOME/conf/httpd.conf.

    Alias /static 'c:/static/' 
    <Directory 'c:/static/'> 
     Options Indexes MultiViews 
     AllowOverride None 
     Order allow,deny 
     Allow from all 




    3) Third step : download mod_jk2.



    mod_jk2 is available on Jakarta's 'binary downloads' page, under the name 'Tomcat Web Server Connectors'.

    Copy the mod_jk2 library into the APACHE_HOME/modules directory.

    Add this line at the end of APACHE_HOME/conf/httpd.conf :

    LoadModule jk2_module modules/ 


    (replace by the name of your mod_jk2 library).





    4) Fourth step : Configure Apache to forward requests to mod_jk2.



    Create a file called APACHE_HOME/conf/

    As an example, if you have 2 web applications, 'webapp1' and 'webapp2', write into that file :

    # Log file, replace APACHE_HOME by your Apache installation directory 
    # Example socket channel, override port and host. 
    # define the worker 
    # Uri mapping 
    # The JBoss JMX Console 
    #The JBoss Web Console 




    5) Fifth step : Use Apache/mod_jk2 as a load balancer.



    Apache/mod_jk2 is commonly used as a software load balancer (see

    Let's edit APACHE_HOME/conf/, add a load balancer that redirects to 2 servers (server1 and server2), and redirect the requests of webapp1 and webapp2 to this load balancer.


    # Log file, replace APACHE_HOME by your Apache installation directory 
    # The load balancer 
    # Server 1, override port and host. 
    # Server 2, override port and host. 
    # define worker for server 1 
    # define worker for server 2 
    # Uri mapping 




    6) Sixth step : Using sticky sessions.



    With the previous configuration, each request is load balanced, either on server1 or server2.


    But when a user opens a Session on one server, it is a good idea to always forward this user's requests to the same server. Otherwise the user's session data would need to be synchronized between both servers.


    This is called a "sticky session", because the user is always using the same server he reached on his first request.


    For achieving this result, two files need to be configured.

    In, each worker must be given a tomcatId :




    On each JBoss server, this tomcatId must be set as a Tomcat jvmRoute.

    The Tomcat server.xml file can be found in server/xxx/deploy/jbossweb-tomcat41.sar/META-INF/jboss-service.xml (JBoss 3.2.3) or

    server/xxx/deploy/jbossweb-tomcat50.sar/server.xml (JBoss 3.2.4 an later).

    In this file, search for :

     <Engine name="MainEngine" defaultHost="localhost">

    And change it into :


     <Engine jvmRoute="server1" name="MainEngine" defaultHost="localhost">


    Caveat: Using the "." (dot) character in jvmRoute/tomcatId (as in e.g. "") seems to break sticky sessions (at least with JBoss 3.2.3 and mod_jk2 2.0.4).




  (Configuring Tomcat  and Apache With JK 1.2)

  ( Apache Tomcat on Linux )


  2.x + Tomcat 4.x + Load Balancing)