在 Apache 中混合使用 RewriteRule 和 ProxyPass
我今天正在调试一个与将 mod_proxy
和 mod_rewrite
混合在一起有关的问题,最终不得不在中使用 balancer://mycluster
RewriteRule
以停止接收来自 Apache 的 404 错误。 我有两个问题:
1)是否有其他方法可以让重写的 URL 通过平衡器,而无需将 balancer://mycluster
添加到 RewriteRule
中?
2)有没有办法定义我在
中定义的所有参数(stickysession=JSESSIONID|jsessionid scolonpathdelim=On lbmethod=bytraffic nofailover=Off)代码>或<代码>重写规则? 我担心与新的 RewriteRule
匹配的请求不会以与通过 ProxyPass
的请求相同的方式进行负载平衡(例如 /app1/something.做
)?
以下是 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/$1.$2 [P,L]
I was working on debugging an issue today related to mixing mod_proxy
and mod_rewrite
together and I ended up having to use balancer://mycluster
in the RewriteRule
in order to stop receiving a 404 error from Apache. I have two questions:
1) Is there any other way to get the rewritten URL to go through the balancer without adding balancer://mycluster
into the 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 RewriteRule
won't load balance in the same fashion as those that go through ProxyPass
(like /app1/something.do
)?
Below are the relevant sections of the httpd.conf. I am using 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/$1.$2 [P,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来我可以使用 ProxySet 指令,因此 URL 是这样的以相同的方式匹配 RewriteRule 负载平衡。
Looks like I can use the ProxySet directive so the URL's that match the RewriteRule load balance in the same fashion.