IIS Reverse proxy/Global URL 重写所有站点的“/api/”文件夹
IIS Reverse proxy/Global URL Rewrite for "/api/" folder for all sites
对于请求位于“/api/”文件夹中的任何站点,我想反向代理对 IIS 实例的任何请求。我设置了一个服务器场,并使用“*”通配符让反向代理为所有内容工作,但是当我想将范围限制为 RegEx 时,它不会 rewrite/proxy 到后端服务器。我在 IIS INSTANCE 级别采取的步骤:
- 设置网络场 - 其中只有一台服务器,machine2
- 为“*”设置重写
- 针对“http://machine1/site1/api/api1”进行了测试 - 它已成功路由到 machine2/site1/api/api1
- 将入站规则从通配符更改为正则表达式
- 将模式更改为'.(/./api/.*)'(没有单引号)
- 针对“http://sarjhennew10vm/site1/api/api1”进行测试
- 请求未路由到机器 2。
下面是我的 applicationHost.config [IIS 的根目录] 的片段。
<rewrite>
<globalRules>
<rule name="ARR_Farm1_loadbalance" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*(\/.*\/api\/.*)" />
<action type="Rewrite" url="http://Farm1/{R:1}" />
</rule>
</globalRules>
</rewrite>
<proxy enabled="true" />
是否可以全局 URL 为特定文件夹实例上的任何站点重新写入服务器场?
编辑:已在下面回答 - 我附上了一张照片以防其他人 运行 加入其中。测试模式对我来说并不清楚 - 并且反驳文档 found here。
你的模式不正确,你可以尝试下面的代码,并将重写 url 更改为 https://Farm1/{R: 0}
<rule name="ARR_Farm1_loadbalance" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*(\/api\/.*)" />
<action type="Rewrite" url="https://Farm1/{R:0}" />
</rule>
对于请求位于“/api/”文件夹中的任何站点,我想反向代理对 IIS 实例的任何请求。我设置了一个服务器场,并使用“*”通配符让反向代理为所有内容工作,但是当我想将范围限制为 RegEx 时,它不会 rewrite/proxy 到后端服务器。我在 IIS INSTANCE 级别采取的步骤:
- 设置网络场 - 其中只有一台服务器,machine2
- 为“*”设置重写
- 针对“http://machine1/site1/api/api1”进行了测试 - 它已成功路由到 machine2/site1/api/api1
- 将入站规则从通配符更改为正则表达式
- 将模式更改为'.(/./api/.*)'(没有单引号)
- 针对“http://sarjhennew10vm/site1/api/api1”进行测试
- 请求未路由到机器 2。
下面是我的 applicationHost.config [IIS 的根目录] 的片段。
<rewrite>
<globalRules>
<rule name="ARR_Farm1_loadbalance" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*(\/.*\/api\/.*)" />
<action type="Rewrite" url="http://Farm1/{R:1}" />
</rule>
</globalRules>
</rewrite>
<proxy enabled="true" />
是否可以全局 URL 为特定文件夹实例上的任何站点重新写入服务器场?
编辑:已在下面回答 - 我附上了一张照片以防其他人 运行 加入其中。测试模式对我来说并不清楚 - 并且反驳文档 found here。
你的模式不正确,你可以尝试下面的代码,并将重写 url 更改为 https://Farm1/{R: 0}
<rule name="ARR_Farm1_loadbalance" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*(\/api\/.*)" />
<action type="Rewrite" url="https://Farm1/{R:0}" />
</rule>