You are here

Apache2 + Tomcat5 + mod_jk

This is a straight forward step-by-step tutorial to set up Apache2 to server java content (jsp and servlets) through tomcat web server using mod_jk.

  1. Install apache2 along with dependencies.
    # apt-get install apache2

  2. Install tomcat5 along with dependencies.
    # apt-get install tomcat5

    Modify /etc/default/tomcat5 to set the correct path to JAVA_HOME directory (jdk needs to be installed and setup prior to installing tomcat). Then restart tomcat.
    # /etc/init.d/tomcat5 restart

    The tomcat5 webserver runs on port 8180 by default in Mepis / Ubuntu.

  3. Install the mod_jk connector and restart apache2 to load the module.
    # apt-get install libapache2-mod-jk
    # /etc/init.d/apache2 restart

    The beauty of installing the distribution specific libapache2-mod-jk package is that it comes pre-configured with all the necessary files and options for using the connector out-of-the-box.

  4. Next you need to edit /etc/apache2/apache2.conf and add the following lines: .

    ##### Begin Tomcat connector configuration #####

    # Where to find workers.properties
    JkWorkersFile /etc/libapache2-mod-jk/workers.properties
    # Where to put jk logs
    JkLogFile /var/log/apache2/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"

    ##### End Tomcat connector configuration #####

  5. Now you have to add directives in /etc/apache2/apache2.conf or in the virtual host ( ... ) section to tell apache which content has to be forward to tomcat. Below are a few examples.

    To send all jsp requests to tomcat, add the line:
    JkMount /* ajp13_worker

    To send servlet for context /jsp-examples:
    JkMount /jsp-examples ajp13_worker

    To send JSPs for context /jsp-examples/*:
    JkMount /jsp-examples/* ajp13_worker

    To send all but /cgi-bin/ requests to tomcat, add:
    JkMount /* ajp13_worker
    JkUnMount /cgi-bin/* ajp13_worker

Category: 

Add new comment