IIS Url 重写 ARR 问题

IIS Url Rewrite ARR issue

我使用 Url 重写模块和 ARR 3 将 IIS 配置为反向代理。 我有一个 public 域,它重定向到我在本地主机上的应用程序。 它工作正常,除非应用程序重定向到另一台主机。 即:重定向到“https://www.google.com/search?q=url+rewrite+iis+arr+3” 我的浏览器显示“http://localhost/search?q=url+rewrite+iis+arr+3” 失败了

托管应用程序使用 Asp Net Mvc with framework.net 4.5。 该应用程序正在使用 IIS 应用程序池配置中的集成管道。

使用 Fiddler,我可以在重定向时看到以下跟踪:

HTTP/1.1 302 Found
Cache-Control: private
Content-Length: 350
Content-Type: text/html; charset=utf-8
Location: http://localhost/search?q=url+rewrite+iis+arr+3
Server: Microsoft-IIS/7.5
X-Powered-By: ARR/3.0
X-Powered-By: ASP.NET
Date: Wed, 02 Nov 2016 16:39:18 GMT

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://www.google.com/search?q=url+rewrite+iis+arr+3">here</a>.</h2>
</body></html>

我的 IIS 配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost/{R:1}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="IsRedirection" stopProcessing="true">
                    <match filterByTags="A" pattern="^http(.*)" negate="false" />
                    <action type="None" />
                </rule>
                <preConditions>
                    <preCondition name="IsRedirection">
                        <add input="{RESPONSE_STATUS}" pattern="3[0-9][0-9]" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

感谢 IIS.net 论坛上的 milope(不知道我是否可以 post link)给我以下解决方案:

In the server level Application Request Routing Cache feature, there is a link that reads: Server Proxy Settings or something like that. Check if the Reverse rewrite host in response header is checked in the Proxy Settings. If so, this may be why external link go to localhost.

这对我有用并解决了我的重定向问题。