我正在IIS 7.5上运行一个HTML,单页面的应用程序。 我想在一个子目录中设置一个反向代理,这样我可以对我的API进行同域请求。
所以我希望我的网站的行为是这样的
+ site/ | - index.html | - app.js | + api/ (reverse proxy to api server)
不幸的是,我错过了一些东西。 虽然我的反向代理重写规则似乎工作,我对index.html的要求不是。 对于超出api / rewrite规则的任何内容,我都会得到500个内部服务器错误。
这是我的web.config:
<rewrite> <outboundRules> <rule name="ReverseProxyOutboundRule1" preCondition="" enabled="true"> <match filterByTags="A, Form, Img" pattern="^http(s)?://webserver/api/(.*)" /> <action type="Rewrite" value="http{R:1}://apiserver/{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://apiserver/{R:1}" /> </rule> </rules> </rewrite>
当我打开请求诊断,我看到错误消息“出站重写规则不能应用于HTTP响应的内容编码(”gzip“)。” 这导致我相信我的出站规则不正确地将请求匹配到index.html。 但我找不出什么问题。
我错过了什么? 我的方法有缺陷吗?
非常感谢。