Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get reverse proxy server's HTTP_HOST in outbound rules of URL Rewrite w/ ARR

I'm using URL Rewrite and Application Request Routing in IIS 7.5 to set up a reverse proxy for a couple of blogs that need to be integrated into existing websites. Multiple domains are bound to one website in IIS, and each one will get a blog that is hosted elsewhere- thats where ARR and URL Rewrite come in. The problem I'm having is that in my outbound ruleset the server variable {HTTP_HOST} pulls the content server's hostname instead of the proxy server's. Is there a server variable that I can use that will give me the proxy server's host hame? Here's a ruleset for one blog with some short comments to clarify:

  <rewrite>
      <rules>
          <rule name="Route requests for contentserver blog" stopProcessing="true">
              <match url="^blog/(.*)" />
              <conditions trackAllCaptures="true">
                  <add input="{CACHE_URL}" pattern="^(https?)://" />
                  <add input="{HTTP_HOST}" pattern="(www\.)proxyserver\.com$" /> <!--this works-->
              </conditions>
              <action type="Rewrite" url="{C:1}://blog.contentserver.com/{R:1}" />
          </rule>
      </rules>
      <outboundRules>
          <rule name="Rewrite Relative URLs" preCondition="ResponseIsHtml" stopProcessing="true">
              <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" negate="false" />
              <action type="Rewrite" value="/blog/{R:1}" />
              <conditions>
                  <add input="{URL}" pattern="^/blog/" />
                  <add input="{HTTP_HOST}" pattern="^(www\.)proxyserver\.com$" /> <!--this doesnt work because it's grabbing the content server's host, not the proxy server's host-->
              </conditions>
          </rule>
          <rule name="Rewrite Absolute URLs" preCondition="ResponseIsHtml" stopProcessing="true">
              <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^(https?)://blog\.contentserver\.com(/(.*))?" />
              <action type="Rewrite" value="/blog/{R:3}" />
              <conditions>
                  <add input="{HTTP_HOST}" pattern="^(www\.)proxyserver\.com$" /> <!--this doesnt work because it's grabbing the content server's host, not the proxy server's host-->
                  <add input="{URL}" pattern="^/blog/" />
              </conditions>
          </rule>
          <preConditions>
              <preCondition name="ResponseIsHtml">
                  <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
              </preCondition>
          </preConditions>
      </outboundRules>
  </rewrite>

Until I figure this out I'm just going to ensure that the blog urls are unique ie, proxyserversite1/blog1 and proxyserversite2/blog2, but I'd like to be able to grab the proxy server host in the outbound rules so i could name them proxyserversite1/blog and proxyserversite2/blog . Any ideas?

like image 661
joelmdev Avatar asked Aug 30 '11 18:08

joelmdev


1 Answers

Add to the inbound rule this:

<serverVariables>
    <set name="HTTP_PRX_HOST" value="{HTTP_HOST}" />
</serverVariables>

Add HTTP_PRX_HOST to allowed server variables (Action Pane->View Server Variables->Add)

Than in your outbound rules use {HTTP_PRX_HOST}

like image 166
Tomek Avatar answered Oct 29 '22 12:10

Tomek