httpd2.2 使用带有 RewriteCond 的反向代理进入无限循环
我想将未设置特定 cookie (c_cntry
) 的传入请求定向,并且请求 URL 没有国家/地区值作为内部服务路径中的第一个元素,该内部服务将尝试找出c_cntry
的正确设置。
但是,当我在浏览器中发送类似 http://localhost:8085/something-to-do
的内容时,我的日志中会出现无休止的递归,并最终在浏览器中出现 502 代理错误。日志似乎显示 ProxyPass 指令中给出的 localhost:9999 没有被触及。
非常感谢您帮助解决这个问题。
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
重写日志:
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) ...
访问日志
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" ...
错误日志
[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=(/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_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)
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=(/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_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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试再添加一个重写条件:
那么您的重写规则应如下所示:
PS
您提供的重写日志 - 我认为这不是实际的重写日志(至少我没有见过这样的格式,其中提到
GET
,200< /code> 之前的响应代码等)。
缴费灵
在进行重写调试时 - 更好地使用
RewriteLogLevel 9
- 它会产生更详细的输出(可能太多,因此不能在工作服务器上使用,但它准确地告诉发生了什么)。Try adding one more rewrite condition:
Then your rewrite rule should look like:
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).