【发布时间】:2020-07-29 16:28:27
【问题描述】:
我有一个 Windows 服务,它在 localhost:5001/api/... 上运行一些带有 REST 端点的应用程序 因此,我安装了带有重写模块的 IIS 10,为该服务的 HTTPS 创建反向代理。效果很好。
现在我想使用同一个 IIS 站点来托管一个网站,它应该在同一个 url 上使用该服务。 所以我尝试将我的 iis 重写 url 的模式更改为 'api/(.*)' 所以它应该只是代理 /api 请求。测试模式正是我想要的:浏览 server.domain/api/function 匹配并且重写完成并且 server.domain 没有被重写。 但是现在浏览 server.domain 经常会返回“HTTP Error 500.52 - URL Rewrite Module Error”。 有时加载页面效果很好。但是重新加载后我会再次收到该错误。
我的 web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:5001/(.*)" />
<action type="Rewrite" value="https://server.domain/{R:2}" />
</rule>
<rule name="ReverseProxyOutboundRule2" preCondition="ResponseIsHtml1" enabled="true">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:5001/(.*)" />
<action type="Rewrite" value="https://server.domain/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="api/(.*)" />
<action type="Rewrite" url="http://localhost:5001/{R:0}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
<httpErrors errorMode="Detailed" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS, DELETE, PUT" />
<add name="Access-Control-Max-Age" value="1000" />
<add name="Access-Control-Allow-Headers" value="x-requested-with, Content-Type, origin, authorization, accept, client-security-token" />
</customHeaders>
</httpProtocol>
<urlCompression doDynamicCompression="false" />
</system.webServer>
</configuration>
我不知道为什么有两个 outboundRules。当我决定创建反向代理规则时,IIS 自动创建了它们。
如果我禁用静态内容压缩,一切都会正常工作。 未安装动态压缩模块。
所以我有多个问题: - 为什么不应该重写的页面出现“重写 URL”错误,而重写的页面可以正常工作 - 为什么静态压缩会产生重写 url 错误 - 我应该如何配置我的 IIS 来进行压缩和重写(我检查了模块顺序,静态压缩模块在重写模块之上)。
最好, 罗宾
【问题讨论】:
标签: iis url-rewriting