Search code examples
apachetomcatubuntuurl-rewritingmod-jk

Mapping a URL between Apache and Tomcat, using mod_jk


I am using Apache/2.2.14 and Apache Tomcat/6.0.29 in a Ubuntu Server 10.04.3 LTS.

This is my jk.conf:

JkWorkersFile /etc/libapache2-mod-jk/workers.properties
JkMount       /portal/* worker1
JkLogLevel    debug
JkMountCopy   All

And this is my workers.properties:

ps=/

# Define 1 real worker named worker1
worker.list=worker1

# Set properties for worker named worker1 to use ajp13 protocol,
# and run on port 8009
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=1
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300

The problem is that whenever I try to access tomcat via apache with: http://my.host.com/portal, tomcat replies with:

13:39:30,683 INFO  [PortalImpl:3829] Current URL /portal/ generates exception: null

The problem goes away if I use a different mountpoint for the worker:

JkMount       /portal/* worker1

But this forces me to access my tomcat instance here: http://my.host.com, which I do not want.

Is there any way of rewriting the URL using mod-jk?


Solution

  • You can skip all that configuration if you just use mod_proxy instead of mod_ajp...

    ProxyPass /foo http://localhost:8080/bar
    ProxyPassReverse /foo http://localhost:8080/bar
    

    This will proxy /foo to local server URL /bar running on port 8080.