You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2015/12/16 23:34:45 UTC
[users@httpd] ProxyPass + Redirect
All,
I've got a reverse-proxy in front of Tomcat that I'd like to configure.
When using mod_jk, we have a configuration like this:
RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
JkMount /foo/*.do myWorker
This works swimmingly.
Now, we have an environment where we need to use mod_proxy instead, so
we have tried this:
RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
ProxyPass /foo/ http://localhost:8009/foo/
ProxyPassReverse /foo/ http://localhost:8009/foo/
(There may be typos in there, but I typed it from memory and sanitized
it at the same time. Don't worry too much about that; the order and gist
is correct.)
Sharp-eyed readers will note that ProxyPass will take precedence over
the RedirectMatch directive. No problem, we can just un-proxy that
special path:
RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
ProxyPass /foo/index.html !
ProxyPass /foo/ http://localhost:8009/foo/
ProxyPassReverse /foo/ http://localhost:8009/foo/
Unfortunately, this doesn't seem to be working for me: a request for
/foo/index.html gives me a 404 error *and a JSESSIONID from Tomcat*, so
I'm fairly certain that the request is being proxied.
I'm certain that I have some small error in my configuration for the
index.html case, but I think I'm up against a wall when it comes to the
/foo/ case: the RedirectMatch looks for ^/foo(/)?$ which is necessarily
the "root" of the virtual-directory being proxied... so I'm going to
need to tell mod_proxy to turn-off proxying for a specific URL.
I know that using mod_rewrite, we can use the [P] flag to send things
through mod_proxy. Is there a do-not-proxy flag for mod_rewrite that I
can use? Or do I have to change from using ProxyPass to using
RewriteRule with [P] for everything instead? I'd prefer a solution that
doesn't involve mod_rewrite if I can get away with it.
Thanks,
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] ProxyPass + Redirect
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Bill,
On 12/16/15 5:45 PM, William A Rowe Jr wrote:
> On Wed, Dec 16, 2015 at 4:34 PM, Christopher Schultz
> <chris@christopherschultz.net <ma...@christopherschultz.net>> wrote:
>
>
> RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
> RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
> ProxyPass /foo/index.html !
> ProxyPass /foo/ http://localhost:8009/foo/
> ProxyPassReverse /foo/ http://localhost:8009/foo/
>
> Unfortunately, this doesn't seem to be working for me: a request for
> /foo/index.html gives me a 404 error *and a JSESSIONID from Tomcat*, so
> I'm fairly certain that the request is being proxied.
>
>
> I thought this was order-sensitive, try reversing the two ProxyPass
> statements.
I actually had the "ProxyPass !" last, and when it didn't work as I
expected, then I re-read the docs which say that ProxyPass has
first-match-wins semantics. So no joy there. :(
Also, this is never going to work:
ProxyPass /foo/ !
ProxyPass /foo/ http://localhost:8009/foo/
So I need a plan for the exact string "/foo/" without shooting-out the
knees of the rest of the proxy configuration.
Any ideas?
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] ProxyPass + Redirect
Posted by William A Rowe Jr <wr...@rowe-clan.net>.
On Wed, Dec 16, 2015 at 4:34 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:
>
> RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
> RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
> ProxyPass /foo/index.html !
> ProxyPass /foo/ http://localhost:8009/foo/
> ProxyPassReverse /foo/ http://localhost:8009/foo/
>
> Unfortunately, this doesn't seem to be working for me: a request for
> /foo/index.html gives me a 404 error *and a JSESSIONID from Tomcat*, so
> I'm fairly certain that the request is being proxied.
>
I thought this was order-sensitive, try reversing the two ProxyPass
statements.
Re: [users@httpd] ProxyPass + Redirect
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Yann,
On 12/17/15 3:51 AM, Yann Ylavic wrote:
> On Thu, Dec 17, 2015 at 8:14 AM, Marat Khalili <mk...@rqc.ru> wrote:
>> Crude, but what about:
>>
>> ProxyPassMatch "^/foo/(.+)$" "http://localhost:8009/foo/$1"
>
> or (along the lines):
> ProxyPassMatch ^/foo/((?!index\.html$).+)$ http://localhost:8009/foo/$1
I was able to solve the problem in this way, which is basically the same
thing you have above:
ProxyPassMatch ^/foo/index.html$ !
ProxyPassMatch ^/foo(/)?$ !
RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
RedirectMatch ^/foo/$ /foo/someplace_specific.html
It's pretty clear that I should probably combine each of these pairs of
directives into single ones, since they will likely perform better. I'm
not sure if PCRE is smart enough to understand that ^whatever$ can be
optimized to straight-equals to avoid the overhead of the whole regular
expression engine.
If anyone knows the answer to that, it would be nice to know. In the
meantime, regular expressions have come to the rescue.
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] ProxyPass + Redirect
Posted by Yann Ylavic <yl...@gmail.com>.
On Thu, Dec 17, 2015 at 8:14 AM, Marat Khalili <mk...@rqc.ru> wrote:
> Crude, but what about:
>
> ProxyPassMatch "^/foo/(.+)$" "http://localhost:8009/foo/$1"
or (along the lines):
ProxyPassMatch ^/foo/((?!index\.html$).+)$ http://localhost:8009/foo/$1
Regards,
Yann.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] ProxyPass + Redirect
Posted by Marat Khalili <mk...@rqc.ru>.
Crude, but what about:
ProxyPassMatch "^/foo/(.+)$" "http://localhost:8009/foo/$1"
? (not sure about + escaping, can be \+)
--
With Best Regards,
Marat Khalili
On 17/12/15 01:34, Christopher Schultz wrote:
> All,
>
> I've got a reverse-proxy in front of Tomcat that I'd like to configure.
> When using mod_jk, we have a configuration like this:
>
> RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
> RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
> JkMount /foo/*.do myWorker
>
> This works swimmingly.
>
> Now, we have an environment where we need to use mod_proxy instead, so
> we have tried this:
>
> RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
> RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
>
> ProxyPass /foo/ http://localhost:8009/foo/
> ProxyPassReverse /foo/ http://localhost:8009/foo/
>
> (There may be typos in there, but I typed it from memory and sanitized
> it at the same time. Don't worry too much about that; the order and gist
> is correct.)
>
> Sharp-eyed readers will note that ProxyPass will take precedence over
> the RedirectMatch directive. No problem, we can just un-proxy that
> special path:
>
> RedirectMatch ^/foo(/)?$ /foo/someplace_specific.html
> RedirectMatch ^/foo/index.html$ /foo/someplace_specific.html
> ProxyPass /foo/index.html !
> ProxyPass /foo/ http://localhost:8009/foo/
> ProxyPassReverse /foo/ http://localhost:8009/foo/
>
> Unfortunately, this doesn't seem to be working for me: a request for
> /foo/index.html gives me a 404 error *and a JSESSIONID from Tomcat*, so
> I'm fairly certain that the request is being proxied.
>
> I'm certain that I have some small error in my configuration for the
> index.html case, but I think I'm up against a wall when it comes to the
> /foo/ case: the RedirectMatch looks for ^/foo(/)?$ which is necessarily
> the "root" of the virtual-directory being proxied... so I'm going to
> need to tell mod_proxy to turn-off proxying for a specific URL.
>
> I know that using mod_rewrite, we can use the [P] flag to send things
> through mod_proxy. Is there a do-not-proxy flag for mod_rewrite that I
> can use? Or do I have to change from using ProxyPass to using
> RewriteRule with [P] for everything instead? I'd prefer a solution that
> doesn't involve mod_rewrite if I can get away with it.
>
> Thanks,
> -chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>