IIS Url Rewrite 覆盖外部 url

标签 iis url-rewriting url-rewrite-module

在我的开发机器上,我试图将 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管理器中选择服务器节点
  • 转到应用请求路由缓存
  • 点击服务器代理设置
  • 取消选中“响应 header 中的反向重写主机”
  • 关于IIS Url Rewrite 覆盖外部 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45209279/

    相关文章:

    regex - .htaccess : Removing unwanted symbols from the end of the URL

    asp.net - 在 Web Gardens 中添加动态路由

    asp.net - 带有 URL 重写模块的 IIS 7.5 在回发时将 QueryString 参数加倍

    iis-7 - IIS7 urlrewrite 模块 - 外部 xml 文件中的规则

    IIS URL 重写否定条件不起作用

    c# - 如何将文件上传到 IIS 中托管的 .NET 3.5 WCF 服务?

    windows - IIS 7.5 Windows 身份验证失败,返回 401

    c# - 不允许 httpclient 后异步返回方法 (405)

    iis - 将静态内容重写到 IIS 中的不同域

    wcf - 如何在WCF中修复 “could not find a base address that matches schema http”…