httpd2.2 使用带有 RewriteCond 的反向代理进入无限循环

发布于 2024-11-28 08:38:11 字数 5271 浏览 3 评论 0原文

我想将未设置特定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪意 2024-12-05 08:38:11

尝试再添加一个重写条件:

RewriteCond %{REQUEST_URI} !^/GeoDiscover

那么您的重写规则应如下所示:

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

PS
您提供的重写日志 - 我认为这不是实际的重写日志(至少我没有见过这样的格式,其中提到GET200< /code> 之前的响应代码等)。

缴费灵
在进行重写调试时 - 更好地使用 RewriteLogLevel 9 - 它会产生更详细的输出(可能太多,因此不能在工作服务器上使用,但它准确地告诉发生了什么)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文