开发者

httpd2.2 using reverse proxy with RewriteCond goes into infinite loop

I want to direct incoming requests that do not a specific cookie set (c_cntry) and the request URL does not have a country value as the first element in path to an internal service that will attempt to figure out the right setting of c_cntry.

But when I send something like http://localhost:8085/something-to-do in the browser, I get an endless recursion in my logs, and an eventual 502 Proxy Error in the browser. The logs seem to show that localhost:9999 given in ProxyPass directive is not being touched.

Will greatly appreciate your help in resolving this problem.

httpd.conf

RewriteLogLevel 3

RewriteRule .*\.php$ - [L]

#req doesnot have country nor is a good cookie present -- send it for geo-discovery

RewriteCond %{REQUEST_URI} !^/(usa|india)/
RewriteCond %{HTTTP_COOKIE} !u_cntry=(usa|india)
RewriteRule (.*) /GeoDiscover?orig=($1)  [QSA,P]

ProxyRequests Off
ProxyPreserveHost On
ProxyTimeout 5
ProxyPass /GeoDiscover http://localhost:9999/GeoDiscover connectiontimeout=1 timeout=3 retry=3 
ProxyPassReverse /GeoDiscover http://localhost:9999/GeoDiscover

REWRITE LOG:

127.0.0.1 - - [06/Aug/2011:12:07:58 +0530] "GET /ex2.php HTTP/1.1" 200 42 server:some-server-name file:C:/myhtdocs/ex2.php
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /something-to-do HTTP/1.1" 502 409 server:some-server-name file:proxy:http://localhost:8085/GeoDiscover?orig=(/something-to-do)
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /GeoDiscover?orig=(/something-to-do) HTTP/1.1" 502 401 server:some-server-name file:proxy:http://localhost:8085/GeoDiscover?orig=(/GeoDiscover)&orig=(/something-to-do)
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /GeoDiscover?orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/something-to-do) HTTP/1.1" 502 401 server:some-server-name file:proxy:http://localhost:8085/GeoDiscover?orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/something-to-do)
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /GeoDiscover?orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/something-to-do) HTTP/1.1" 502 401 server:some-server-name file:proxy:http://localhost:8085/GeoDiscover?orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/something-to-do) ...

ACCESS LOG

127.0.0.1 - - [06/Aug/2011:12:07:58 +0530] "GET /ex2.php HTTP/1.1" 200 42 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1" "-" "-"
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /something-to-do HTTP/1.1" 502 409 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1" "127.0.0.1" "localhost:8085"
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /GeoDiscover?orig=(/something-to-do) HTTP/1.1" 502 401 "-" "Mozilla/5.0(Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1" "127.0.0.1, 127.0.0.1" "localhost:8085, localhost:8085"
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /GeoDiscover?orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/something-to-do) HTTP/1.1" 502 401 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1" "127.0.0.1, 127.0.0.1, 127.0.0.1,
127.0.0.1" "localhost:8085, localhost:8085, localhost:8085, localhost:8085"
127.0.0.1 - - [06/Aug/2011:12:08:02 +0530] "GET /GeoDiscover?orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/GeoDiscover)&orig=(/something-to-do) HTTP/1.1" 502 401 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1" "127.0.0.1, 127.0.0.1, 127.0.0.1,
127.0.0.1, 127.0.0.1" "localhost:8085, localhost:8085, localhost:8085, localhost:8085, localhost:8085" ...

ERROR LOG

[Sat Aug 06 12:08:02 2011] [debug] mod_proxy_htttp.c(56): proxy: HTTP: canonicalising URL //localhost:8085/GeoDiscover
[Sat Aug 06 12:08:02 2011] [debug] proxy_util.c(1525): [client 127.0.0.1] proxy: *: found reverse proxy worker for http://localhost:8085/GeoDiscover?orig=(/so开发者_如何学编程mething-to-do)
[Sat Aug 06 12:08:02 2011] [debug] mod_proxy.c(1015): Running scheme http handler (attempt 0)
[Sat Aug 06 12:08:02 2011] [debug] mod_proxy_htttp.c(1973): proxy: HTTP: serving URL http://localhost:8085/GeoDiscover?orig=(/something-to-do)
[Sat Aug 06 12:08:02 2011] [debug] proxy_util.c(2011): proxy: HTTP: has acquired connection for (*)
[Sat Aug 06 12:08:02 2011] [debug] proxy_util.c(2067): proxy: connecting http://localhost:8085/GeoDiscover?orig=(/something-to-do) to localhost:8085
[Sat Aug 06 12:08:02 2011] [debug] proxy_util.c(2193): proxy: connected /GeoDiscover?orig=(/something-to-do) to localhost:8085
[Sat Aug 06 12:08:02 2011] [debug] proxy_util.c(2444): proxy: HTTP: fam 2 socket created to connect to *
[Sat Aug 06 12:08:02 2011] [debug] proxy_util.c(2576): proxy: HTTP: connection complete to 127.0.0.1:8085 (localhost)
[Sat Aug 06 12:08:02 2011] [debug] mod_proxy_http.c(56): proxy: HTTP: canonicalising URL //localhost:8085/GeoDiscover^M [Sat Aug 06 12:08:02 2011] [debug] proxy_util.c(1525): [client 127.0.0.1] proxy: *: found reverse proxy worker for http://localhost:8085/GeoDiscover?orig=(/GeoDiscover)&orig=(/something-to-do)
[Sat Aug 06 12:08:02 2011] [debug] mod_proxy.c(1015): Running scheme http handler (attempt 0
[Sat Aug 06 12:08:02 2011] [debug] mod_proxy_http.c(1973): proxy: HTTP: serving URL http://localhost:8085/GeoDiscover?orig=(/GeoDiscover)&orig=(/something-to-do)


Try adding one more rewrite condition:

RewriteCond %{REQUEST_URI} !^/GeoDiscover

Then your rewrite rule should look like:

RewriteCond %{REQUEST_URI} !^/(usa|india)/
RewriteCond %{REQUEST_URI} !^/GeoDiscover
RewriteCond %{HTTTP_COOKIE} !u_cntry=(usa|india)
RewriteRule (.*) /GeoDiscover?orig=($1)  [QSA,P]

P.S. The rewrite log you have provided -- I do not think it is the actual rewrite log (at least I have not seen such format which mentions GET, 200 Response code etc before).

P.P.S. When doing rewrite debugging -- better use RewriteLogLevel 9 -- it produces more detailed output (possibly too much, so cannot be used on working server, but it tells exactly what is going on).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜