You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andres Riancho <an...@gmail.com> on 2009/03/02 03:21:14 UTC
JkMount a different location
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.
Cheers,
--
Andrés Riancho
http://www.bonsai-sec.com/
http://w3af.sourceforge.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: JkMount a different location
Posted by Andres Riancho <an...@gmail.com>.
Rainer,
On Mon, Mar 2, 2009 at 12:29 PM, Rainer Jung <ra...@kippdata.de> wrote:
> 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.
I got the idea, and I was able to successfully implement it. I was
going in the right direction with the RewriteRule stuff, I actually
wrote something like:
RewriteRule ^/xxx/(.*)$ /yyy/$1
Myself, but the *most important* thing, that allows you to rewrite and
use mod_jk is the [PT] flags for the rule!
RewriteRule ^/xxx/(.*)$ /yyy/$1 [PT]
> 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.
Yes, I truly think that mod_jk needs to address this on its own.
Thank you very much for your help,
Cheers,
> Regards,
>
> Rainer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
--
Andrés Riancho
http://www.bonsai-sec.com/
http://w3af.sourceforge.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: JkMount a different location
Posted by Rainer Jung <ra...@kippdata.de>.
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.
Regards,
Rainer
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org