Jon*_*ter 6 apache configuration interpolation localhost proxypass
我正在尝试设置一个apache服务器用于测试目的.目标是模拟负载均衡器.我们试图模拟的部分只是接受客户端安全的httprequest,并使用proxypass将其(通过不安全的http)传递给正确的服务器.这一切都100%有效.
问题是这样的:我想在几个开发环境中使用这个"负载均衡器".为了能够测试应用程序的服务器端,我希望proxypass使用变量URL传递给客户端IP.这将需要在proxypass规则中使用变量URL.我找到了变量REMOTE_ADDR,但我似乎无法在proxypass规则中使用它.我首先尝试了apache网站告诉我使用的语法,但这没有用(为http:// REMOTE_ADDR/foobar /获取DNS查找失败).我知道我必须用Interpolate做一些事情,但我似乎无法弄清楚到底是什么.
这行做它应该做的,所以服务器工作得很好:
ProxyPass/http:// localhost:81 /
这些是我尝试过的规则(使用变量)失败了.
ProxyPass/http:// $ {REMOTE_ADDR}:81/
错误:[client 127.0.0.1] proxy:DNS查找失败:$ {remote_addr}返回/
ProxyPass/https://% {REMOTE_ADDR} s/
错误:[client 127.0.0.1] proxy:DNS查找失败:%{remote_addr}由/返回
ProxyPassInterpolateEnv On
...
ProxyPass/http:// $ {REMOTE_ADDR}:81/interpolate
错误:[client 127.0.0.1]错误解析URL //:81:无效的主机/端口
任何想法的人?
小智 13
对于插值情况,它应该是这样的:
RewriteEngine on
RewriteMap lowercase int:tolower
#This sets the variable to env:
RewriteRule ^ - [E=SERVER_NAME:${lowercase:%{SERVER_NAME}}]
#Now interpolate makes variables available for proxypass & proxypassreverse:
ProxyPassInterpolateEnv On
ProxyPass / ajp://${SERVER_NAME}:8009/ interpolate
ProxyPassReverse / ajp://${SERVER_NAME}:8009/ interpolate
Run Code Online (Sandbox Code Playgroud)
在互联网上搜索了一整晚后,我找不到任何明确的案例,如此或任何答案.不过我终于明白了.
您可以使用[P]代码替换mod_rewrite规则的Proxypass指令,P表示代理.
Mod_rewrite会让你做更具体的事情.
| 归档时间: |
|
| 查看次数: |
15239 次 |
| 最近记录: |