Reverse proxy with mod_rewrite using RewriteRule [P]

Reverse proxy with mod_rewrite using RewriteRule [P]

am 02.03.2010 17:06:46 von dalopez

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]

In RewriteLog we can see that the rewrite rule is working fine up to
some point:

192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#eef078/initial] (2) init rewrite engine
with requested uri /something
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#eef078/initial] (3) applying pattern
'^/(.*)' to uri '/something'
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#eef078/initial] (2) rewrite '/something'
-> 'http://something.mysite.es/'
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#eef078/initial] (2) forcing
proxy-throughput with http://something.mysite.es/
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#eef078/initial] (1) go-ahead with proxy
request proxy:http://something.mysite.es/ [OK]

Good, that is what we want, but it seems like something.mysite.es is not
being sent to the Apache 2.2.11 but to the reverse proxy Apache itself,
because the log follows:

192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#ef3088/initial] (2) init rewrite engine
with requested uri /public/index.aspx
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#ef3088/initial] (3) applying pattern
'^/(.*)' to uri '/public/index.aspx'
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#ef3088/initial] (2) rewrite
'/public/index.aspx' -> 'http://public/index.aspx.mysite.es/'
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#ef3088/initial] (2) forcing
proxy-throughput with http://public/index.aspx.mysite.es/
192.168.24.X - - [02/Mar/2010:15:46:19 +0100]
[pre.mysite.es/sid#db73a0][rid#ef3088/initial] (1) go-ahead with proxy
request proxy:http://public/index.aspx.mysite.es/ [OK]

Which of course leads to failure because of not being able to resolve
domain name "public". A ping to something.mysite.es shows that it is
being resolved to 192.168.24.Y, which is correct.

Any clue?

Thank you very much.

Daniel


Protección de Datos: ACOTELSA le informa de que los datos facilitados por Ud. y utilizados para el envío de esta comunicación serán objeto de tratamiento automatizado o no en nuestros ficheros, con la finalidad de gestionar la agenda de contactos de nuestra empresa y para el envío de comunicaciones profesionales por cualquier medio electrónico o no. Vd. podrá en cualquier momento ejercer el derecho de acceso, rectificación, cancelación y oposición en los términos establecidos en la Ley Orgánica 15/1999. El responsable del tratamiento es ACOTELSA, con domicilio en Ronda de Poniente, 3 bajo, 28760 Tres Cantos, Madrid.

Confidencialidad El contenido de esta comunicación, así como el de toda la documentación anexa, es confidencial y va dirigido únicamente al destinatario del mismo. En el supuesto de que usted no fuera el destinatario, le solicitamos que nos lo indique y no comunique su contenido a terceros, procediendo a su destrucción. Gracias.

Confidenciality The content of this communication and any attached information is confidential and exclusively for the use of the addressee. If you are not the addressee, we ask you to notify to the sender and do not pass its content to another person, and please be sure you destroy it. Thank you.



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

Re: Reverse proxy with mod_rewrite using RewriteRule

am 02.03.2010 17:53:28 von Tom Evans

2010/3/2 Daniel López Robles :
> 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 ne=
ed
> 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

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

Re: Reverse proxy with mod_rewrite using RewriteRule[P]

am 03.03.2010 18:17:12 von dalopez

Tom Evans escribió:
> 2010/3/2 Daniel López Robles :
>
>> 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


Protección de Datos: ACOTELSA le informa de que los datos facilitados por Ud. y utilizados para el envío de esta comunicación serán objeto de tratamiento automatizado o no en nuestros ficheros, con la finalidad de gestionar la agenda de contactos de nuestra empresa y para el envío de comunicaciones profesionales por cualquier medio electrónico o no. Vd. podrá en cualquier momento ejercer el derecho de acceso, rectificación, cancelación y oposición en los términos establecidos en la Ley Orgánica 15/1999. El responsable del tratamiento es ACOTELSA, con domicilio en Ronda de Poniente, 3 bajo, 28760 Tres Cantos, Madrid.

Confidencialidad El contenido de esta comunicación, así como el de toda la documentación anexa, es confidencial y va dirigido únicamente al destinatario del mismo. En el supuesto de que usted no fuera el destinatario, le solicitamos que nos lo indique y no comunique su contenido a terceros, procediendo a su destrucción. Gracias.

Confidenciality The content of this communication and any attached information is confidential and exclusively for the use of the addressee. If you are not the addressee, we ask you to notify to the sender and do not pass its content to another person, and please be sure you destroy it. Thank you.



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

Re: Reverse proxy with mod_rewrite using RewriteRule

am 03.03.2010 18:41:31 von Tom Evans

2010/3/3 Daniel López Robles :
> Tom Evans escribió:
>>
>> 2010/3/2 Daniel López Robles :
>>
>>>
>>> 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 so=
me
>>> 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 se=
ems
> 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 o=
ne:
>
> 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 lo=
oks
> like the request is being sent from the reverse proxy to the Apache 2.2.1=
1
> 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 for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Reverse proxy with mod_rewrite using RewriteRule

am 04.03.2010 10:13:36 von Philip Wigg

> I don't get it, I must be missing something. Any clue, please?

You're possibly in a situation where your rewrite rule is matching
against subsequent requests, causing a loop.

For example:-

1. You make a request to /something/ which is proxied by your rule to
http://www.mysite.es/something/

2. The back-end server send a 301 redirect to
http://www.mysite.es/something/public/index.asp

3. The client browser sends a request to
http://www.mysite.es/something/public/index.asp, which is the picked
up by your rule and internally rewritten and proxied to
http://www.mysite.es/something/something/public/index.asp.

And this continues. I think there's probably a better way to do what
you want but I'm not sure exactly what it is you're trying to do. As
other posters have suggested, it might involve using the ProxyPass
directive.

Hope that helps.

Cheers,
Phil.

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