How to setup Apache Tomcat Connector on Linux Centos 5.x

7
Sep
1

The Problem

On myserver, I have a Java app myapp running off Tomcat that I can access on port 8080
http://myserver.com:8080/myapp/

I wanted to serve that app through Apache so I can access it at
http://myapp.myserver.com/


The Solution

So I needed to setup the Apache Tomcat Connector for myserver
a Linux box running CentOS release 5.3

  1. To get started go to the docs
    http://tomcat.apache.org/connectors-doc/

  2. under headlines, click on the link that says
    “Download the binaries for selected platforms”

    It is recommended to use the binary version if one is available. If the binary is not available, follow the instructions for building mod_jk from source.
    To download mod_jk source select one of the mirrors here.

  3. Download the appropriate connector for your platform. For me that was:
    http://apache.mirror.aussiehq.net.au/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.28/i586/mod_jk-1.2.28-httpd-2.2.X.so

  4. rename the connector file
    from:

    mod_jk-1.2.28-httpd-2.2.X.so

    to:

    mod_jk.so

  5. and place the file in your Apache’s modules directory
    in my case, the modules directory is at

    /usr/lib/httpd/modules/

  6. Now make the below changes to httpd.conf file
    my conf file is at

    /etc/httpd/conf/httpd.conf

    Add this line at the end of your httpd.conf after replacing $TOMCAT_HOME with the correct path for your Tomcat installation:

    Include $TOMCAT_HOME/conf/auto/mod_jk.conf

    for me that line looks like:

    Include /usr/share/tomcat5/conf/jk/mod_jk.conf

  7. create mod_jk.conf file at:

    /usr/share/tomcat5/conf/jk/mod_jk.conf

  8. and add this code to it:

    <IfModule !mod_jk.c>
      LoadModule jk_module "/usr/lib/httpd/modules/mod_jk.so"
    </IfModule>
     
    JkWorkersFile "/usr/share/tomcat5/conf/jk/workers.properties"
    JkLogFile "/usr/share/tomcat5/logs/mod_jk.log"
     
    JkLogLevel debug
     
    <VirtualHost *:80>
       ServerName myapp.myserver.com
       DocumentRoot "/usr/share/tomcat5/webapps/myapp"
       <Directory "/usr/share/tomcat5/webapps/myapp">
         Options None
         AllowOverride None
         Order allow,deny
         allow from all
       </Directory>
       ErrorLog logs/app1-error.log
       JkMount  /GDM/* gdmw
       JkMount  /* gdmw
       JkMount  /GDM gdmw
    </VirtualHost>

    This will tell Apache to use directives in the mod_jk.conf file in the Apache configuration.

  9. Create workers.properties file at

    $TOMCAT_HOME/conf/jk/workers.properties

    For me I had to create

    /usr/share/tomcat5/conf/jk/workers.properties

  10. add this code to workers.properties:

    worker.list=myappw
    worker.myappw.host=myapp.myserver.com
    worker.myappw.port=8009
    worker.myappw.type=ajp13
    worker.myappw.lbfactor=1

  11. Add the listener to the Engine element in the server.xml in your Tomcat:

    /usr/share/tomcat5/conf/server.xml

    for tomcat 5.x:

    ...
      <Engine ...>
        ...
        <Listener className="org.apache.jk.config.ApacheConfig" modJk="/path/to/mod_jk.so" />
        ...
      </Engine>
      ...

    For me that was:

     <Listener className="org.apache.jk.config.ApacheConfig" modJk="/usr/lib/httpd/modules/mod_jk.so" />

  12. Then restart Tomcat.

  13. Restart httpd (Apache web server).

  14. Done!!

Conclusion

So what’s a ‘worker’?

A Tomcat worker is a Tomcat instance that is waiting to execute servlets or any other content on behalf of some web server.

Now each time Apache receives a request at http://myapp.myserver.com/*
Apache forwards the servlet requests to the worker called “myappw” running in the background.

So now you can access that servlet by going to
http://myapp.myserver.com/

instead of
http://myserver.com:8080/myapp/

Found this useful?

Why not subscribe to my RSS feed!

Filed under: Apache, Linux, Tomcat

// 1 Comment

  1. umesh
    4:36 pm on March 25th, 2011

    Not working ,, now if i add Include /usr/tomcat6/conf/jk/mod_jk.conf to httpd.conf http does not load .. it gives

    Reloading httpd: not reloading due to configuration syntax error
    [FAILED]

    please suggest

Leave a comment

RSS feed for comments on this post