Do I need to use ProxyPassReverse if I'm using mod rewrite?

后端 未结 1 459
醉话见心
醉话见心 2020-12-15 07:13

I am using mod rewrite to mask the context root of my application. For example,

RewriteRule ^/directory/(.*) balancer://appcluster/directory/$1 [P]
<         


        
相关标签:
1条回答
  • 2020-12-15 07:29

    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 use ProxyPassReverse 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.

    0 讨论(0)
提交回复
热议问题