Iis 7 如何获得反向代理服务器&x27;s HTTP_主机在URL重写的出站规则中w/ARR

Iis 7 如何获得反向代理服务器&x27;s HTTP_主机在URL重写的出站规则中w/ARR,iis-7,url-rewriting,Iis 7,Url Rewriting,我正在使用IIS7.5中的URL重写和应用程序请求路由为几个需要集成到现有网站中的博客设置反向代理。在IIS中,多个域绑定到一个网站,每个域都会得到一个在其他地方托管的博客——这就是ARR和URL重写的用武之地。我遇到的问题是,在出站规则集中,服务器变量{HTTP_HOST}提取内容服务器的主机名,而不是代理服务器的主机名。是否有一个服务器变量可以让我使用代理服务器的主机hame?下面是一个博客的规则集,其中有一些简短的评论要澄清: <rewrite> <rul

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

  <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。有什么想法吗?

在入站规则中添加以下内容:

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

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


比在您的出站规则中使用{HTTP\u PRX\u HOST}

好!我要试一试!