Re: Reverse proxy with mod_rewrite using RewriteRule [P]

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

 



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


Protecci�e Datos: ACOTELSA le informa de que los datos facilitados por Ud. y utilizados para el env�de esta comunicaci�er�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�de comunicaciones profesionales por cualquier medio electr�o o no. Vd. podr�n cualquier momento ejercer el derecho de acceso, rectificaci�cancelaci� oposici�n los t�inos establecidos en la Ley Org�ca 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�as�omo el de toda la documentaci�nexa, es confidencial y va dirigido �mente 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�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 <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