tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Jung <>
Subject Re: JkMount a different location
Date Mon, 02 Mar 2009 14:29:12 GMT
On 02.03.2009 03:21, Andres Riancho wrote:
> List,
>      I've search the Tomcat FAQ, but I haven't been able to find any
> answers, so... here is my question... I have a JSP application
> deployed in Tomcat inside the "/abc/" directory; and I want to be able
> to access it from *two different locations* from Apache, for example,
> when I access: "http://apache/abc/" and "http://apache/123/abc/". The
> first JkMount is trivial:
>          JkMount /abc ajp13_worker
>          JkMount /abc/* ajp13_worker
>      And is working as expected, but for the second... I don't have the
> slightest clue on how to do it... I tried mod_rewrite, but it seems
> that it isn't possible to combine JkMount's and URL rewrites in a
> successful way. Could anyone point me in the right direction? Thanks!
>      I'm using Apache2, Tomcat6.

I'll give an answer for Apache 2.2 and yes, this is missing in the 
documentation at the moment. For IIS there is a builtin rewrite feature 
in mod_jk, but not for httpd, because httpd can already do it on its own.

Context rewriting for mod_jk and Apache httpd

Tested with httpd 2.2.11.

You need to handle three things:

1) Rewrite the URL /xxx/something to /yyy/something before the request 
gets send to Tomcat

2) Change any redirects you get back from Tomcat, which point to 
locations /yyy/somethingelse, into location /xxx/somethingelse

3) Change pathes of cookies, which might get set by the application from 
/yyy to /xxx.

The module mod_proxy allow sto do this via ProxyPass, ProxyPassReverse 
and ProxyPassReverseCookiePath directives. But you can't use mod_proxy 
and mod_jk for the same requests.

The first directive can be replaced by some RewriteRule, the other two 
cases will be handled by dynamically changing response headers.

So lets start with

JkMount /yyy/* myworker

and now:

ad 1) RewriteRule ^/xxx/(.*)$ /yyy/$1 [PT]

This will change any rquest /xxx/something into /yyy/something before 
passing it to mod_jk.

ad 2) Header edit Location ^([^/]*//[^/]*)?/yyy/(.*)$ $1/xxx/$2

This changes Location headers, the headers used for signalling a 
redirect to the client.

Any URL of the form "protocol://server:port/yyy/something" will be 
changed (yyy -> xxx), as well as URLs of the form "/yyy/something".

Happy regular expression studying.

ad 3) Header edit Set-Cookie "^(.*; Path=)/yyy([/;].*)?$" $1/xxx$2

This changes Set-Cookie headers, the headers used for setting a cookie.

I hope you get the idea.

In case your webapp puts self referential links into he response pages 
themselves, things get more complicated (or say: more expensive in terms 
of CPU cycles). Then you must parse the complete response pages to do 
search and replace. You can do that e.g. with mod_substitute or mod_sed 
or mod_proxy_html.

It seems it would be nice, mod_jk had short hand notations for 1)-3). 
You can file an enhancement request in bugzilla for this, if you like.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message