【发布时间】:2019-11-08 18:37:41
【问题描述】:
我知道有很多关于反向代理的文章,有很多关于InBound 和OutBound 的东西,但我想知道我做错了什么。
我有 NodeJs 服务器,在 http://192.168.0.1:3000 上可用
当我通过如下所示的服务器场创建反向代理时
模式:*
动作类型:Route To Server Farm
方案:http,服务器场: FarmName,路径: {R:0}
当我浏览 http://localhost 时,一切都像魅力一样,但问题是基于子域或子文件夹请求。
我想要代理 http://localhost/site/sub1 到 http://192.168.0.1:3000 我建立了 InBound 和 OutBound 规则如下:
<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 错误,例如:
错误:404
糟糕,找不到页面
抱歉,您请求的页面不存在或已被删除!
在私有 Rocket 服务器中我可以看到
[34mI20190129-17:17:04.122(3.5) rocketchat:logger server.js:199 [34mMeteor ➔ 方法 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 }
如果 RewriteAbsoluteUrlsInResponse 和 RewriteRelativePaths 正常工作,为什么我会从 NodeJS 收到 404 错误?
【问题讨论】:
标签: node.js iis url-rewriting reverse-proxy rocket.chat