{"id":1678,"date":"2012-11-06T17:54:19","date_gmt":"2012-11-06T09:54:19","guid":{"rendered":"http:\/\/rmohan.com\/?p=1678"},"modified":"2012-11-06T17:57:20","modified_gmt":"2012-11-06T09:57:20","slug":"proxypassreverse","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1678","title":{"rendered":"ProxyPassReverse"},"content":{"rendered":"<p>am using mod rewrite to mask the context root of my application. For example,<\/p>\n<pre><code>RewriteRule ^\/directory\/(.*) balancer:\/\/appcluster\/directory\/$1 [P] <\/code><\/pre>\n<p>The appcluster looks like this:<\/p>\n<pre><code>&lt;Proxy balancer:\/\/appcluster&gt; 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 &lt;\/Proxy&gt; <\/code><\/pre>\n<p>Do I need to use <code>ProxyPassReverse<\/code> at all? I used to use it because my old webserver code looked like this:<\/p>\n<pre><code>ProxyPass \/App balancer:\/\/appcluster lbmethod=byrequests stickysession=JSESSIONID|jsessionid timeout=120 nofailover=On ProxyPassReverse \/App http:\/\/localhost:9013\/App <br \/><br \/><br \/><br \/><\/code><\/pre>\n<div>\n<p>The <code>ProxyPassReverse<\/code> 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 <a href=\"http:\/\/localhost:9013\/\" rel=\"nofollow\">http:\/\/localhost:9013\/<\/a>, and it tries to redirect the browser to, say, <code>\/new_location\/<\/code>, then it will respond with a redirect and location header of <a href=\"http:\/\/localhost:9013\/new_location\/\" rel=\"nofollow\">http:\/\/localhost:9013\/new_location\/<\/a>, and Apache will take this and send it off to the browser. Problem is, the browser (assuming it&#8217;s somewhere else) then tries to send a request to <a href=\"http:\/\/localhost:9013\/new_location\/\" rel=\"nofollow\">http:\/\/localhost:9013\/new_location\/<\/a>, and gets an error.<\/p>\n<p>What ProxyPassReverse does is intercepts those headers, and rewrites them so that they match what the Apache server that&#8217;s doing the proxying looks like. So if my apache server is hosting <a href=\"http:\/\/myhost.com\/\" rel=\"nofollow\">http:\/\/myhost.com\/<\/a> and I have a <code>ProxyPass<\/code> that points <code>\/<\/code> to <a href=\"http:\/\/localhost:9013\/App\" rel=\"nofollow\">http:\/\/localhost:9013\/App<\/a>, if the application sitting at localhost:9013 returns a redirect to <a href=\"http:\/\/localhost:9013\/App\/new_location\/\" rel=\"nofollow\">http:\/\/localhost:9013\/App\/new_location\/<\/a>, I&#8217;ll need to use <code>ProxyPassReverse<\/code> so that it gets rewritten to <a href=\"http:\/\/myhost.com\/new_location\/\" rel=\"nofollow\">http:\/\/myhost.com\/new_location\/<\/a> by Apache before sending the request back to the browser.<\/p>\n<p>If you aren&#8217;t issuing redirects, it&#8217;s not going to be an issue, but it doesn&#8217;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.<\/p>\n<\/div>\n<pre><code><br \/><br \/><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>am using mod rewrite to mask the context root of my application. For example,<\/p>\n<p> RewriteRule ^\/directory\/(.*) balancer:\/\/appcluster\/directory\/$1 [P] <\/p>\n<p>The appcluster looks like this:<\/p>\n<p> &lt;Proxy balancer:\/\/appcluster&gt; 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 &lt;\/Proxy&gt; <\/p>\n<p>Do I need to use ProxyPassReverse at all? I used to use it because my [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1678"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1678"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1678\/revisions"}],"predecessor-version":[{"id":1682,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1678\/revisions\/1682"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}