在我的开发机器上,我试图将 IIS 配置为反向代理,以将来自端口 443 的请求转发到本地运行的 nodejs 应用程序。
请求转发得很好,但有时 nodejs 应用程序尝试将浏览器重定向到外部站点,并且 IIS url 重写模块更改也指向本地服务器。
我正在使用 https://localhost/test 访问该站点
IIS 将请求重新路由到节点应用程序 http://localhost:14819/test
节点应用程序返回一个 http 302,位置 header 设置为 https://example.com/someroute
IIS 将其转换为 https://localhost/someroute
我希望外部 url 不受 IIS 的影响。这该怎么做?
这是我的 Web.config 内容
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule1" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^test(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^localhost" />
</conditions>
<action type="Rewrite" url="http://localhost:14819/test{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
最佳答案
If you have any redirect coming back from the backend proxy and you do not want to redirect the Location header coming ,You can do that by unchecking "Reverse rewritehost in response headers" in Application Request Routing
关于IIS Url Rewrite 覆盖外部 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45209279/