我试图设置一个反向代理,使用这里 , 这里和这里的教程。
该站点在localhost:8080上设置,反向代理使用localhost:8080/myProxy 。
处理标准链接时,一切正常。 我可以查看代理url,并按预期查看一切。 从localhost:8080/myProxy/default.aspx的链接到预期的localhost:8080/myProxy/about.aspx 。
我遇到的问题是在使用.NET Response.Redirect()情况下,URL会更改为网站的实际位置而不是代理。
即链接从localhost:8080/myproxy/default.aspx – > localhost:8080/about.aspx 。
我该如何解决这个问题?
这是我的configuration:
<system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <urlCompression doStaticCompression="false" doDynamicCompression="false" dynamicCompressionBeforeCache="false" /> <rewrite> <rules> <rule name="Reverse Proxy to my site" stopProcessing="true"> <match url="^myProxy/(.*)" /> <action type="Rewrite" url="http://localhost:8080/{R:1}" /> </rule> </rules> <outboundRules> <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1"> <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://localhost:8080/(.*)" /> <action type="Rewrite" value="/myProxy/{R:2}" /> </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="/myProxy/{R:1}" /> </rule> <preConditions> <preCondition name="ResponseIsHtml1"> <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> </preCondition> </preConditions> </outboundRules> </rewrite> </system.webServer>
抱歉回答我自己的问题,但我认为这是值得放在那里为他人信息:
使用Response.Redirect ,出站规则起作用。 通过Fiddler查看请求帮助解决了链接的问题。
Response.Redirect()试图发送到/About.aspx (在响应头中传输)。
这并没有被正则expression式拾取。
我需要的唯一出站规则是设置Response_location ,如下所示:
<rule name="Response Status Update" preCondition="ResponseStatus" stopProcessing="true"> <match serverVariable="RESPONSE_Location" pattern="^/(.*)" /> <action type="Rewrite" value="http://myServer:8080/myProxy/{R:1}" /> </rule>
入站规则保持不变。