如果我使用 mod 重写,是否需要使用 ProxyPassReverse?
我正在使用 mod rewrite 来屏蔽应用程序的上下文根。例如,
RewriteRule ^/directory/(.*) balancer://appcluster/directory/$1 [P]
appcluster 如下所示:
<Proxy balancer://appcluster>
BalancerMember http://localhost:8080/App route=app_01 keepalive=On loadfactor=1 ttl=300 min=3 smax=5 max=15
ProxySet lbmethod=byrequests stickysession=JSESSIONID|jsessionid timeout=120 nofailover=On
</Proxy>
我需要使用 ProxyPassReverse 吗?我曾经使用它,因为我的旧网络服务器代码如下所示:
ProxyPass /App balancer://appcluster lbmethod=byrequests stickysession=JSESSIONID|jsessionid timeout=120 nofailover=On
ProxyPassReverse /App http://localhost:9013/App
I am using mod rewrite to mask the context root of my application. For example,
RewriteRule ^/directory/(.*) balancer://appcluster/directory/$1 [P]
The appcluster looks like this:
<Proxy balancer://appcluster>
BalancerMember http://localhost:8080/App route=app_01 keepalive=On loadfactor=1 ttl=300 min=3 smax=5 max=15
ProxySet lbmethod=byrequests stickysession=JSESSIONID|jsessionid timeout=120 nofailover=On
</Proxy>
Do I need to use ProxyPassReverse
at all? I used to use it because my old webserver code looked like this:
ProxyPass /App balancer://appcluster lbmethod=byrequests stickysession=JSESSIONID|jsessionid timeout=120 nofailover=On
ProxyPassReverse /App http://localhost:9013/App
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ProxyPassReverse
用于在 Apache 将应用程序 (appcluster) 发送到 Apache 的标头发送到浏览器之前更改它。例如,如果应用程序位于 http://localhost:9013/,并且它尝试将浏览器重定向到,例如,/new_location/
,那么它将使用重定向和位置标头 http://localhost:9013/new_location/,Apache 会将其发送到浏览器。问题是,浏览器(假设它在其他地方)然后尝试将请求发送到 http://localhost:9013/new_location/ ,并收到错误。ProxyPassReverse 的作用是拦截这些标头,并重写它们,以便它们与执行代理的 Apache 服务器的外观相匹配。因此,如果我的 apache 服务器托管 http://myhost.com/ 并且我有一个
ProxyPass
将/
指向 http://localhost:9013/App,如果应用程序坐在 localhost:9013 返回重定向到 http://localhost:9013/App/new_location/,我需要使用 ProxyPassReverse< /code> 以便在发送之前由 Apache 重写为 http://myhost.com/new_location/请求返回给浏览器。如果您不发出重定向,这不会成为问题,但如果返回 301/302 重定向,将其放在那里也没什么坏处。就 mod_rewrite 而言,RewriteRule 适用于发往应用程序的请求,而不适用于来自应用程序的响应。所以它们是互斥的事件。
The
ProxyPassReverse
is used to change the headers sent by the app (appcluster) to Apache, before Apache sends it the browser. For example, if the app sits at http://localhost:9013/, and it tries to redirect the browser to, say,/new_location/
, then it will respond with a redirect and location header of http://localhost:9013/new_location/, and Apache will take this and send it off to the browser. Problem is, the browser (assuming it's somewhere else) then tries to send a request to http://localhost:9013/new_location/, and gets an error.What ProxyPassReverse does is intercepts those headers, and rewrites them so that they match what the Apache server that's doing the proxying looks like. So if my apache server is hosting http://myhost.com/ and I have a
ProxyPass
that points/
to http://localhost:9013/App, if the application sitting at localhost:9013 returns a redirect to http://localhost:9013/App/new_location/, I'll need to useProxyPassReverse
so that it gets rewritten to http://myhost.com/new_location/ by Apache before sending the request back to the browser.If you aren't issuing redirects, it's not going to be an issue, but it doesn't hurt to have it there in case a 301/302 redirect is returned. As far as mod_rewrite, the RewriteRule applies to the request going to the App, and not the response coming from the App. So they are mutually exclusive events.