在 Apache 中混合使用 RewriteRule 和 ProxyPass
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/879241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mixing RewriteRule and ProxyPass in Apache
提问by Taylor Leese
I was working on debugging an issue today related to mixing mod_proxyand mod_rewritetogether and I ended up having to use balancer://myclusterin the RewriteRulein order to stop receiving a 404 error from Apache. I have two questions:
今天我正在调试一个与混合mod_proxy和mod_rewrite一起相关的问题,我最终不得不使用balancer://myclusterinRewriteRule以停止接收来自 Apache 的 404 错误。我有两个问题:
1) Is there any other way to get the rewritten URL to go through the balancer without adding balancer://myclusterinto the RewriteRule?
1)有没有其他方法可以让重写的URL通过平衡器而不添加balancer://mycluster到RewriteRule?
2) Is there a way to define all the parameters I defined in ProxyPass(stickysession=JSESSIONID|jsessionid scolonpathdelim=On lbmethod=bytraffic nofailover=Off) in either the <Proxy>or RewriteRule? I'm concerned the requests that match the new RewriteRulewon't load balance in the same fashion as those that go through ProxyPass(like /app1/something.do)?
2)有没有一种方法来定义我中定义的所有参数ProxyPass(stickysession = JSESSIONID |无论是在JSESSIONID scolonpathdelim =在lbmethod = bytraffic nofailover = OFF)<Proxy>或RewriteRule?我担心与新请求匹配的请求不会以与通过的请求RewriteRule相同的方式进行负载平衡ProxyPass(例如/app1/something.do)?
Below are the relevant sections of the httpd.conf. I am using Apache 2.2.
以下是 httpd.conf 的相关部分。我正在使用 Apache 2.2。
<Proxy balancer://mycluster>
Order deny,allow
Allow from all
BalancerMember ajp://my.domain.com:8009 route=node1
BalancerMember ajp://my.domain.com:8009 route=node2
</Proxy>
ProxyPass /app1 balancer://mycluster/app1 stickysession=JSESSIONID|jsessionid scolonpathdelim=On lbmethod=bytraffic nofailover=Off
ProxyPassReverse /app1 ajp://my.domain.com:8009/app1
...
...
RewriteRule ^/static/cms/image/(.*)\.(.*) balancer://mycluster/app1/. [P,L]
采纳答案by Taylor Leese
Looks like I can use the ProxySetdirective so the URL's that match the RewriteRule load balance in the same fashion.
看起来我可以使用ProxySet指令,以便以相同的方式匹配 RewriteRule 负载平衡的 URL。
<Proxy balancer://mycluster>
Order deny,allow
Allow from all
BalancerMember ajp://my.domain.com:8009 route=node1
BalancerMember ajp://my.domain.com:8009 route=node2
ProxySet stickysession=JSESSIONID|jsessionid scolonpathdelim=On lbmethod=bytraffic nofailover=Off
</Proxy>

