IIS 10 重写为 http 和 https 的内部端口

IIS 10 rewrite to internal port for both http and https

我在 Windows 服务器的端口 8080 上有一个节点 js 应用程序 运行,并且可以通过 http://localhost:8080 从服务器内部访问。我想使用一些子域,如 app.mydomain.com,而不使用服务器外部的端口号来打开这个 node.js 应用程序。我想完全将所有流量重写到这个端口并且没有子目录的过滤器。

我已经在我的 IIS 上安装了 ARRv3_0urlrewrite2 并且也重新启动了服务器。还在服务器上安装了一个证书并分配给这个 IIS 网站。目前,我正在使用此文件作为我的 web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Reverse Proxy to node server" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:8080/{R:1}" />
                </rule>              
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

另外,我也在网站目录下创建了一个index.html文件,但是没有区别。

当我使用 httphttps 打开域时,我得到 404。

有一些小技巧需要注意。

  1. 您需要在 ARR 中勾选启用代理。 ARR->服务器代理设置->启用代理。
  2. 根据你的代理规则,当你从一个URL代理到另一个时,只会重写域,所以你必须确保URL中有页面信息,这样如http://localhost:8080/html,最后改写为http://localhost:8080/index.html。如果您不想添加 index.html,您可以启用默认文档并将 index.html 移动到第一个。