Re: Reverse proxy with mod_rewrite using RewriteRule [P]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/3/3 Daniel López Robles <dalopez@xxxxxxxxxxxx>:
> Tom Evans escribió:
>>
>> 2010/3/2 Daniel López Robles <dalopez@xxxxxxxxxxxx>:
>>
>>>
>>> Hello:
>>>
>>> We have two Apaches in a server:
>>>
>>> Apache 2.2.14, reverse proxy, listening to IP 192.168.24.X
>>> Apache 2.2.11, which actually serves the websites, listening to IP
>>> 192.168.24.Y
>>>
>>> Domain name proxy.mysite.es points to our reverse proxy Apache, and we
>>> need
>>> it to send requests to the other Apache in this way:
>>>
>>> http://proxy.mysite.es/something -> http://something.mysite.es
>>>
>>> Our rewrite rule:
>>>
>>> RewriteRule ^/(.*) http://$1.mysite.es/ [L,P]
>>>
>>
>> This looks very wrong.
>>
>>
>>>
>>> In RewriteLog we can see that the rewrite rule is working fine up to some
>>> point:
>>> ....
>>> [pre.mysite.es/sid#db73a0][rid#eef078/initial] (2) rewrite '/something'
>>> ->
>>> 'http://something.mysite.es/'
>>> ...
>>> [pre.mysite.es/sid#db73a0][rid#ef3088/initial] (2) rewrite
>>> '/public/index.aspx' -> 'http://public/index.aspx.mysite.es/'
>>>
>>
>> as these two lines point out.
>>
>> If you request the URL http://proxy.mysite.es/foo/bar.html on the
>> proxy, your rule says to rewrite this to http://foo/bar.html.mysite.es
>> - does that LOOK right?!
>>
>> I would do this much more explicitly, rather than allow the users to
>> specify the hosts that we will proxy to:
>>
>> ProxyPass /something/ http://something.mysite.es/
>> ProxyPassReverse /something/ http://something.mysite.es/
>> ProxyPassReverseCookieDomain something.mysite.es proxy.mysite.es
>>
>> and then repeat those lines for each host that you wish to be proxied.
>>
>> If you really can't do this, and must have it dynamic, then I suggest
>> a regular expression tutorial :)
>>
>> Cheers
>>
>> Tom
>>
>
> Yes, you are right, Tom, if the user requests
> "http//proxy.mysite.es/something/public/index.aspx" it will be rewritten to
> "http//something/public/index.aspx.mysite.es/" that is of course not
> correct. I know this is not the best RewriteRule directive. The question is
> that if http//proxy.mysite.es/something/ is being properly rewritten as
> http//something.mysite.es/, and http://something.mysite.es redirects to
> http://something.mysite.es/public/index.aspx, why is being logged the
> attempt to rewrite "'/public/index.aspx' ->
> 'http://public/index.aspx.mysite.es/'" in the reverse proxy Apache? It seems
> that the http//something.mysite.es/ request is being sent to the reverse
> proxy Apache itself.
>
> Actually, I have changed the RewriteRule directive for a more explicity one:
>
> RewriteRule ^/something/(.*) http://www.mysite.es/$1 [L,P]
>
> And some kind of infinite loop is being created. RewriteLog:
>
> 192.168.24.X - - [03/Mar/2010:17:23:50 +0100]
> [proxy.mysite.es/sid#dbb478][rid#ef0130/initial] (2) init rewrite engine
> with requested uri /something/
> 192.168.24.X - - [03/Mar/2010:17:23:50 +0100]
> [proxy.mysite.es/sid#dbb478][rid#ef0130/initial] (3) applying pattern
> '^/something/(.*)' to uri '/something/'
> 192.168.24.X - - [03/Mar/2010:17:23:50 +0100]
> [proxy.mysite.es/sid#dbb478][rid#ef0130/initial] (2) rewrite '/something/'
> -> 'http://www.mysite.es/'
> 192.168.24.X - - [03/Mar/2010:17:23:50 +0100]
> [proxy.mysite.es/sid#dbb478][rid#ef0130/initial] (2) forcing
> proxy-throughput with http://www.mysite.es/
> 192.168.24.X - - [03/Mar/2010:17:23:50 +0100]
> [proxy.mysite.es/sid#dbb478][rid#ef0130/initial] (1) go-ahead with proxy
> request proxy:http://www.mysite.es/ [OK]
> [...] Then, those 5 lines again and again.
>
> But if I look the access log of the Apache that actually serves
> www.mysite.es, I can see also a lot of request at the same time, so it looks
> like the request is being sent from the reverse proxy to the Apache 2.2.11
> and back a lot of times.
>
> 192.168.24.Y - - [03/Mar/2010:17:23:52 +0100] "GET / HTTP/1.0" 302 191 "-"
> "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; WOW64; SV1; .NET CLR
> 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR
> 3.5.30729)"
> [...] Again and again.
>
> I don't get it, I must be missing something. Any clue, please?
>
> Thank you very much.
>
> Daniel
>

Here's the big clue: stop using rewrite rules for proxying! If you
want to pass requests for http://proxy.mysite.es/something/ to
http://www.mysite.es/, then use ProxyPass - it is what it was written
for.

I'm not seeing an infinite loop in your rewrite log - that looks
normal to me. The access log from your application server
(www.mysite.es) shows that it is redirecting when the proxy requests
/. I imagine that is getting passed to your browser, which then
follows the redirect again. If it is looping, it is the redirection on
your application server that is causing it.

Cheers

Tom

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux