tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Jung <>
Subject Re: jk_mod and binding tomcat's root to an apache directory
Date Sun, 04 Nov 2007 12:43:30 GMT

actually there are two things to discuss here:

1) How to express rules which requests should be forwarded
2) Rewriting URLs

and finally, how does one combine the two.

Concerning 1)

First the case, where you don't want to rewrite the URL, e.g. the
browser really asks for /servlet-examples-URLs directly.

Then you would simply use

JkMount /servlet-examples/* myworker

(and myworker is a placeholder for the name of your worker).

In case you want to also forward the exact URL /servlet-examples, but
e.g. not /servlet-examples2, you can combine

JkMount /servlet-examples/* myworker
JkMount /servlet-examples/ myworker

into one line:

JkMount /servlet-examples|/* myworker

Concerning 2)

You can rewrite URLs via mod_rewrite. For your example a very basic
configuration (based on httpd 2.2) would be

LoadModule rewrite_module modules/
RewriteEngine On
RewriteRule /tomcat/(.*) /servlet-examples/$1

Since you want to combine the rewriting with mod_jk, i.e. mod_jk should
forward the rewritten URL, and not the original URL, you need to add the
PT flag to the rewrite rule (see mod_rewrite docs in httpd docs).

RewriteRule /tomcat/(.*) /servlet-examples/$1 [PT]

Now this will mean, that also the JkMount will be matched against the
rewritten rule.

In most cases it will be more adequate to really add JkMounts like

JkMount /servlet-examples|/* myworker

because you want to manage forwardingby the actual contexts/webapps
deployed on the backends. If you *really* want to forward based on the
original URL, you can do this in httpd 2.2 with another extension of the
rewrite rules:

RewriteRule /tomcat/(.*) /servlet-examples/$1

This will set the handler to jakarta-servlet, which activates JK
forwarding for this request even without any matching JkMount, and the
forwarding takes the name of the worker out of the environment variable
JK_WORKER_NAME, which we set to myworker.

Even without rewriting, the setup is zero-admin, as long as there is no
new context deployed. The exact servlets do not matter. Whenever you add
another webapp, e.g. jsp-examples, you need to add another config line,
either when using JkMount and doing no URL rewriting, or when using

You can though deploy your webapps not on the top level directory, but
instead into a sub directory (using a path, that contains more than one
URL directory component), e.g. /tomcat/servlet-examples etc. directly on
your tomcat, and then JkMount /tomcat/*. That'll be true zero-admin.

I hope that's understandable :)



Shug Boabby schrieb:
> Hello everyone,
> There does not appear to be a separate list for mod_jk discussions... so
> I assume this is the most relevant place to ask questions. Please let me
> know if there is somewhere more specific for me to bring this.
> I have mod_jk up and running with Apache 2 and Tomcat 5.5. However, it
> seems that every single servlet must be mapped by hand in the apache
> config files! This seems like a lot of work to me. What I'd really like
> to do would be to map my server's "/tomcat" path to redirect any
> requests to Tomcat's root. e.g. a request coming in to my server at
> /tomcat/servlet-examples would be re-routed to Tomcat's /servlet-examples
> Such a setup would mean zero admin in the Apache-Tomcat bridge when new
> servlets are added. As they are added to Tomcat, they immediately become
> accessible in Apache's /tomcat/ directory. Is it possible to set it up
> this way? It seems a very sensible way to do things.
> Shug

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message