Tomcat – How get I the Tomcat AJP-Connectors working

ajpapache-2.2tomcat

I want to access Tomcat through the Apache-webserver using connectors. I sticked to the documentation: http://tomcat.apache.org/connectors-doc/generic_howto/quick.html
I only modified it a little to match directory-structure used on my Debian-(Squeeze)-System.

So I added the following to /etc/apache2/httpd.conf:

# Load mod_jk module
# Update this path to match your modules location
#LoadModule    jk_module  libexec/mod_jk.so
# Declare the module for <IfModule directive> (remove this line on Apache 2.x)
#AddModule     mod_jk.c
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile     /var/log/apache2/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile     /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Send everything for context /examples to worker named worker1 (ajp13)
JkMount  /tomcat7/* worker1

I commented out the loading of the module, because that already happens, after I installed mod_jk through the package-system (libapache2-mod-jk).

My workers.properties look like this:

# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

Tomcat 7 is installed directly from archive from Apache, because it is not a package in Squeeze. Tomcat 7 is running and reachable under it's own port (8180, to not collide with tomcat6 from the package-system). As far as I understand, I should see now the tomcat-site with http://host/tomcat7/. But I get a 404 instead. What is wrong?


After quanta hinted to set the log-level to debug (thanks) I did that and found the following error-message in mod_jk.log: 'jk_map_to_storage::mod_jk.c (3585): missing uri map for 176.9.9.55:/tomcat7/'. I googled for that and found http://old.nabble.com/mod_jk%2C-missing-uri-map-td23984359.html

So the options set in httpd.conf weren't used in VirtualHosts. I added 'JkMountCopy On' to my VirtualHost – and got first a Tomcat 404 (instead of the httpd 404). Problem here, that he tries to access the exact same URI mounted, so in my case /tomcat7. I used instead the name of the webapp as mount and everything is fine for me.

Best Answer

Make sure that:

  1. you type a trailing slash http://host/tomcat7/, not http://host/tomcat7.
  2. you have a AJP 1.3 connector listen on port 8009 in server.xml:

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    

If it still doesn't work, I suggest you turning on debug and take a look at mod_jk.log.


EDIT:

If you use:

JkMount  /tomcat7/* worker1

and access via http://host/tomcat7, I'm sure you will get the Apache 404 error.

You can specify JkMount in a Virtual Host section which you want:

<VirtualHost *:80>
    ServerName  xx
    ServerAdmin xx

    JkMount /tomcat7 worker1
    JkMount /tomcat7/* worker1
</VirtualHost>