Apache 重写然后代理传递
我有一个 apache 服务器,在我们的 DMZ 中充当反向代理。我们有一个外部服务可以回发到该服务器上的特定 URL。现在需要此服务回发到一个全新的应用程序,但这很可能在不久的将来再次发生变化,因为我们现在正处于测试阶段。
因此,为了解决此问题,我尝试获取传入的回发请求 /smsPostback.php
,并将其重写为新的相对 URL /SMSHandler/Process
。这部分正在发挥作用。
然而,在配置的下面立即定义,我有一个 ProxyPass 指令,用于将 /SMSHandler
的所有流量代理到内部服务器。
这些是 apache conf 文件中的新行:
RewriteRule ^/smsPostback.php$ /SMSHandler/Process
##Proxy pass smshandler
ProxyPass /SMSHandler http://172.29.61.49:8080/SMSHandler
ProxyPassReverse /SMSHandler http://172.29.61.49:8080/SMSHandler
这些是重写日志中的日志:
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) init rewrite engine with requested uri /smsPostback.php
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (3) applying pattern '^/smsPostback.php$' to uri '/smsPostback.php'
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) rewrite '/smsPostback.php' -> '/SMSHandler/Process'
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) local path result: /SMSHandler/Process
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) prefixed with document_root to C:/hidden.com/SMSHandler/Process
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (1) go-ahead with C:/hidden.com/SMSHandler/Process [OK]
这是来自 apache 的错误日志条目:
[Tue Jan 24 18:43:36 2012] [error] [client 172.29.61.49] File does not exist: C:/fmfacilitymaintenance.com/SMSHandler
关于为什么它从不反向代理请求而是尝试(并失败)的任何想法在本地提供服务?谢谢!
I have an apache server that works as a reverse proxy in our DMZ. We have an external service that posts back to a particular URL on this server. There is a need now for this service to postback to an entirely new application, but this will most likely change again in the near future as we're in a testing phase right now.
So to resolve this, I'm trying to take the incoming postback request, /smsPostback.php
, and rewrite it to a new relative URL, /SMSHandler/Process
. This part is working.
However defined immediately below in the config, I have a ProxyPass directive to proxy all traffic to /SMSHandler
to an internal server.
These are the new lines from the apache conf file:
RewriteRule ^/smsPostback.php$ /SMSHandler/Process
##Proxy pass smshandler
ProxyPass /SMSHandler http://172.29.61.49:8080/SMSHandler
ProxyPassReverse /SMSHandler http://172.29.61.49:8080/SMSHandler
And these are the logs from the rewrite log:
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) init rewrite engine with requested uri /smsPostback.php
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (3) applying pattern '^/smsPostback.php
And this is the error log entry from apache:
[Tue Jan 24 18:43:36 2012] [error] [client 172.29.61.49] File does not exist: C:/fmfacilitymaintenance.com/SMSHandler
Any thoughts as to why it never reverse proxies the request, but rather tries (and fails) to serve it locally?? Thanks!
to uri '/smsPostback.php'
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) rewrite '/smsPostback.php' -> '/SMSHandler/Process'
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) local path result: /SMSHandler/Process
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) prefixed with document_root to C:/hidden.com/SMSHandler/Process
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (1) go-ahead with C:/hidden.com/SMSHandler/Process [OK]
And this is the error log entry from apache:
Any thoughts as to why it never reverse proxies the request, but rather tries (and fails) to serve it locally?? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要向 RewriteRule 添加一个
PT
(PassThrough),以便 apache 获取重写的 URI 并通过 URL 处理管道将其传回(以便 mod_proxy 可以处理它)。该规则应如下所示:You need to add a
PT
(PassThrough) to your RewriteRule so that apache takes the rewritten URI and passes it back through the URL handling pipeline (so that mod_proxy can handle it). The rule should look like this: