Apache重写然后代理通行证

Mat*_*att 6 apache mod-rewrite reverse-proxy

我有一个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
Run Code Online (Sandbox Code Playgroud)

这些是重写日志中的日志:

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]
Run Code Online (Sandbox Code Playgroud)

这是来自apache的错误日志条目:

[Tue Jan 24 18:43:36 2012] [error] [client 172.29.61.49] File does not exist: C:/fmfacilitymaintenance.com/SMSHandler
Run Code Online (Sandbox Code Playgroud)

任何想法,为什么它永远不会反向代理请求,而是尝试(并失败)在本地服务?谢谢!

Jon*_*Lin 14

您需要向PTRewriteRule 添加一个(PassThrough),以便apache获取重写的URI并将其传递回URL处理管道(以便mod_proxy可以处理它).该规则应如下所示:

RewriteRule ^/smsPostback.php$ /SMSHandler/Process [L,PT]
Run Code Online (Sandbox Code Playgroud)

  • 你可以删除`Last`,它隐含在Passthrough http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_pt (3认同)