gpt4 book ai didi

node.js - IIS 反向代理从其背后的 NodeJS 获取 404

转载 作者:太空宇宙 更新时间:2023-11-04 01:36:26 24 4
gpt4 key购买 nike

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

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

模式:*
操作类型: 路由到服务器场
方案: 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!

在私有(private) 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 检查网络数据包),该模块发生了冲突。在私有(private)服务器上查找失败的 http 请求,定义出站和入站规则等,但它仍然不起作用。

我必须实现一种解决方法来完成上述场景:

在不同端口 8081 上创建两个网站,位于:
C:\inetpub\wwwrootC:\inetpub\wwwroot1 第一个是正在浏览的主网站http://localhost/site ,第二个可通过 http://localhost:81/reversesite 访问,最后在 C:\inetpub\wwwroot1 (反向站点)的 web.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 上进行反向操作时,它没有按照问题中所述工作。

关于node.js - IIS 反向代理从其背后的 NodeJS 获取 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54423543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com