gpt4 book ai didi

iis-7 - 如何在 URL 重写 w/ARR 的出站规则中获取反向代理服务器的 HTTP_HOST

转载 作者:行者123 更新时间:2023-12-01 22:33:24 25 4
gpt4 key购买 nike

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

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

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

最佳答案

将以下内容添加到入站规则:

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

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

在出站规则中使用 {HTTP_PRX_HOST}

关于iis-7 - 如何在 URL 重写 w/ARR 的出站规则中获取反向代理服务器的 HTTP_HOST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7248123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com