IIS 反向代理从其背后的 NodeJS 获取 404

IIS Reverse proxy get 404 from NodeJS behind it

我知道有很多关于反向代理的文章,有很多关于 InBoundOutBound 的东西,但我想知道我做错了什么。

我有 NodeJs 服务器,可在 http://192.168.0.1:3000 上使用 当我像下面这样通过服务器场创建反向代理时

模式 : *
操作类型: Route To Server Farm
方案: http服务器场: FarmName路径: {R:0}
当我浏览 http://localhost 时,一切正常,但问题是基于子域或子文件夹请求。

我想要代理 http://localhost/site/sub1http://192.168.0.1:3000 我建立了 InBoundOutBound 规则如下:

<rewrite>
  <globalRules>
    <rule name="ARR_testd_loadbalance" enabled="true" stopProcessing="true">
      <match url="^site/sub1(.*)" />
      <action type="Rewrite" url="http://192.168.0.1:3000/{R:1}" />
      <serverVariables>
        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
        <set name="HTTP_ACCEPT_ENCODING" value="" />
      </serverVariables>
    </rule>
    <rule name="query" stopProcessing="true">
      <match url="^sockjs/(.*)" />
      <action type="Rewrite" url="http://192.168.0.1:3000/sockjs/{R:1}" />
    </rule>
  </globalRules>
  <outboundRules>
    <rule name="RewriteAbsoluteUrlsInResponse" preCondition="ResponseIsHtml1">
      <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://192.168.0.1(\:3000)?/(.*)" />
      <action type="Rewrite" value="/site/sub1/{R:3}" />
    </rule> 
    <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml1">
      <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" negate="false" />
      <action type="Rewrite" value="/site/sub1/{R:1}" />
    </rule>
    <rule name="Restore-AcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
      <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)"></match>
      <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}"></action>
    </rule>
    <preConditions>
      <preCondition name="NeedsRestoringAcceptEncoding">
        <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
      </preCondition>
      <preCondition name="ResponseIsHtml1">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>

基于上述规则,我仍然看到来自 NodeJs 服务器的错误为: 从 NodeJS 加载页面时,它显示 404 错误,如:

Error:404
Oops, page not found
Sorry, page you requested does not exists or was deleted!

在私人 Rocket 服务器中我可以看到

[34mI20190129-17:17:04.122(3.5) rocketchat:logger server.js:199 [34mMeteor ➔ method public-settings/get -> userId: null , arguments: [] [34mI20190129-17:17:04.125(3.5) meteor_autoupdate_clientVersions { id: 'TFhMadFtuynon7rHB', clientAddress: '192.168.0.201', httpHeaders: { referer: 'http://localhost/site/sub1', 'x-forwarded-for': '[::1]:3704,192.168.0.201', 'x-forwarded-host': '192.168.0.9:3000', 'x-forwarded-port': '3000', 'x-forwarded-proto': 'http', host: '192.168.0.9:3000', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.116', 'accept-language': 'en-US,en;q=0.9' }, userId: null }

如果 RewriteAbsoluteUrlsInResponseRewriteRelativePaths 正常工作,为什么我从 NodeJS 收到 404 错误?

我不知道为什么它真的不起作用, 当我在任何地址 * 通配符上启用反向代理时,一切都很好,我认为 ARR 模块中发生了一些事情,当我想在 site/sub1 上进行反向工作时,我认为这被违反了,经过多次尝试,比如检查网络数据包Wireshark 在私有服务器上查找失败的 http 请求,定义出站和入站规则等,它仍然不起作用。

我必须实施解决方法才能完成上述情况:

在不同的端口 8081 上创建两个网站,位于:
C:\inetpub\wwwrootC:\inetpub\wwwroot1 第一个是主要网站,正在浏览 http://localhost/site 并且第二个可以通过 http://localhost:81/reversesite 在末尾定义 C:\inetpub\wwwroot1web.config 中的反向规则访问(反向站点),如下所示:

<rewrite>
  <rules>
    <rule name="ReverseProxyInboundRule1" stopProcessing="true">
      <match url="(.*)" />
      <action type="Rewrite" url="http://192.168.0.1:3000/{R:1}" />
    </rule>
  </rules>
</rewrite>

通过浏览 http://localhost:81 它将代理到 http://192.168.0.1:3000 并且没有任何 404 错误。

无论如何,在 http://localhost/site 中,我可以通过 http://localhost:81http://192.168.0.1:3000 调用任何 api 或地址,但是当我试图在 http://localhost/site/sub1 上进行反向操作时没有按照问题中的描述工作。