Configuring Apache 2.2.x with Tomcat 5.5.x

1 Apache side

1.1 mod_jk.so

Get a proper mod_jk.so for your Apache & Tomcat version, put it into the following directory, replace APACHE_HOME with your Apache directory.

   APACHE_HOME/modules

1.2 Editing APACHE_HOME/conf/httpd.conf

Add the following lines,

    LoadModule jk_module modules/mod_jk.so
    JkWorkersFile "conf/workers.properties"
    JkLogFile "logs/mod_jk.log"
    JkMount /*.jsp worker1
    JkMount /*/servlet/* worker1

1.3 Creating workers.properties

Create a file as follows,

    worker.list=worker1
    worker.worker1.type=ajp13
    worker.worker1.host=localhost
    worker.worker1.port=8009

2 Tomcat side

2.1 Editing TOMCAT_HOME/conf/server.xml

Add Context in a Host element as follows, so that you can access JSP and Servlet under "test" context.

    <!-- Test Context -->
    <Context path="/test" docBase="APACHE_HOME/htdocs/test" reloadable="true" 
        crossContext="true"/>

2.2 Editing TOMCAT_HOME/conf/web.xml (Optional)

Users of Tomcat found out they cannot use /servlet/* to invoke their servlet under /WEB-INF/classes path any more since ver 4.1.12. RELEASE-NOTES of ver 4.1.12 or later mention the following change,

Starting with Tomcat 4.1.12, the invoker servlet is no longer available by default in all webapps. Enabling it for all webapps is possible by editing $CATALINA_HOME/conf/web.xml to uncomment the "/servlet/*" servlet-mapping definition.

Using the invoker servlet in a production environment is not recommended and is unsupported. More details are available on the Tomcat FAQ at http://tomcat.apache.org/faq/misc.html#invoker.

However, users have to uncomment another place in web.xml since Tomcat 5.0, although official documentation does not mention it.

Instead of trying harder to fix this security bug, some developers just declared that, "Using /servlet/ to map servlets is evil, absolutely evil". This solution is convenient, absolutely convenient.

In a nutshell, you need to uncomment the following tags,

    <servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>

2.3 Editing TOMCAT_HOME/conf/tomcat-users.xml (Optional)

Add roles and users if necessary.

1