【问题标题】:How to get reverse proxy server's HTTP_HOST in outbound rules of URL Rewrite w/ ARR如何在 URL Rewrite w/ARR 的出站规则中获取反向代理服务器的 HTTP_HOST
【发布时间】:2011-11-07 01:37:15
【问题描述】:

我正在使用 IIS 7.5 中的 URL 重写和应用程序请求路由来为需要集成到现有网站的几个博客设置反向代理。多个域绑定到 IIS 中的一个网站,每个域都将获得一个托管在其他地方的博客 - 这就是 ARR 和 URL 重写的来源。我遇到的问题是在我的出站规则集中服务器变量 {HTTP_HOST} 拉内容服务器的主机名,而不是代理服务器的。是否有一个我可以使用的服务器变量会给我代理服务器的主机hame?这是一个博客的规则集,需要澄清一些简短的 cmets:

  <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>

在我弄清楚这一点之前,我只是要确保博客 url 是唯一的,即 proxyserversite1/blog1 和 proxyserversite2/blog2,但我希望能够在出站规则中获取代理服务器主机,所以我可以将它们命名为 proxyserversite1/blog 和 proxyserversite2/blog 。有什么想法吗?

【问题讨论】:

    标签: iis-7 url-rewriting


    【解决方案1】:

    在入站规则中添加:

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

    将 HTTP_PRX_HOST 添加到允许的服务器变量(操作窗格->查看服务器变量->添加)

    比在您的出站规则中使用 {HTTP_PRX_HOST}

    【讨论】:

    • 太棒了!我会试一试!
    猜你喜欢
    • 2013-01-28
    • 2016-09-10
    • 2012-04-26
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2016-03-07
    相关资源
    最近更新 更多