使用 IIS7、ARR 和 & 设置反向代理时出现出站规则问题网址重写

发布于 2024-11-30 10:47:52 字数 2182 浏览 4 评论 0 原文

我正在尝试为网站设置反向代理,大致如本文所述:http://blogs.msdn.com/b/carlosag/archive/2010/04/02/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr。 aspx

我遇到的问题是我的出站规则没有一致应用,而且我也找不到它们始终失败的模式。有时,当我重新启动 IIS 并发出请求时,出站规则会成功应用,有时则不会。但当我刷新页面时,响应始终不包含重写的网址。下面是我正在使用的规则集,它相当于上面链接中的规则集,所以我认为规则不是问题。 IIS 中一定有一些我缺少的设置。该应用程序当前托管在我的本地计算机(localhost)上:

 <system.webServer>
    <rewrite>
        <rules>
            <rule name="Route the requests for blog" stopProcessing="true">
                <match url="^blog/(.*)" />
                <conditions>
                    <add input="{CACHE_URL}" pattern="^(https?)://" />
                </conditions>
                <action type="Rewrite" url="{C:1}://www.mysite.com/{R:1}" />
                <serverVariables>
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables>
            </rule>
        </rules>
        <outboundRules>
            <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://www.mysite.com/(.*)" />
                <action type="Rewrite" value="/blog/{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="/blog/{R:1}" />
            </rule>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
</system.webServer>

这篇文章经过编辑以使用更简单的规则集。

I'm trying to set up a reverse proxy for a website roughly as outlined in this article: http://blogs.msdn.com/b/carlosag/archive/2010/04/02/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr.aspx

The problem that I'm having is that my outbound rules aren't consistently applied, and I can't find a pattern where they consistently fail either. Sometimes when I restart IIS and make a request the outbound rules successfully applied, other times not. But consistently when I refresh the page the response contains no rewritten urls. Below is the ruleset that I'm using which is equivalent to the ruleset in the link above, so I don't think the rules are the issue. There must be some setting in IIS that I'm missing. This application is currently hosted on my local machine (localhost):

 <system.webServer>
    <rewrite>
        <rules>
            <rule name="Route the requests for blog" stopProcessing="true">
                <match url="^blog/(.*)" />
                <conditions>
                    <add input="{CACHE_URL}" pattern="^(https?)://" />
                </conditions>
                <action type="Rewrite" url="{C:1}://www.mysite.com/{R:1}" />
                <serverVariables>
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables>
            </rule>
        </rules>
        <outboundRules>
            <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://www.mysite.com/(.*)" />
                <action type="Rewrite" value="/blog/{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="/blog/{R:1}" />
            </rule>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
</system.webServer>

This post was edited to use a simpler ruleset.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文