【问题标题】:IIS Reverse Proxy Apply outbound rule on specific pathIIS 反向代理在特定路径上应用出站规则
【发布时间】:2016-03-07 08:38:15
【问题描述】:

我定义了以下入站和出站规则以使我的反向代理正常工作。

<rewrite>
    <rules>
        <rule name="Route the requests for backend app" stopProcessing="true">
            <match url="^foldera/folderb/(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="www.site1.com" />
            </conditions>
            <action type="Rewrite" url="http://www.site2.com/{R:1}" />
            <serverVariables>
                <set name="HTTP_ACCEPT_ENCODING" value="" />
            </serverVariables>
        </rule>
    </rules>
    <outboundRules>
        <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml" enabled="true" stopProcessing="false">
            <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" />
            <action type="Rewrite" value="/foldera/folderb/{R:1}" />
            <conditions>
                <add input="{URL}" pattern="^/foldera/folderb/.*" />
            </conditions>
        </rule>
        <preConditions>
            <preCondition name="ResponseIsHtml">
                <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
            </preCondition>
        </preConditions>
    </outboundRules>
</rewrite>

现在,站点“http://www.site2.com/”已正确加载到“http://www.site1.com/foldera/folderb/”中,并且出站规则确保将站点 2 中的每个资源都重写为 http://www.site1.com/foldera/folderb/{resourcefromsite1} 不幸的是,出站规则也使我网站的其他部分崩溃。可能是因为他试图将每个本机资源重写为相同的“http://www.site1.com/foldera/folderb/”文件夹结构。 如何使出站规则仅响应通过路径 http://www.site1.com/foldera/folderb/ 而不是通过 http://www.site1.com/foldera 请求/加载的资源

干杯 杰伦

【问题讨论】:

    标签: iis proxy reverse rule outbound


    【解决方案1】:

    您非常接近解决方案。要解决这个问题,您必须在 preCondition 中添加 {URL} 作为输入。你的重写规则最终应该是这样的:

    <rewrite>
        <rules>
            <rule name="Route the requests for backend app" stopProcessing="true">
                <match url="^foldera/folderb/(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="www.site1.com" />
                </conditions>
                <action type="Rewrite" url="http://www.site2.com/{R:1}" />
                <serverVariables>
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables>
            </rule>
        </rules>
        <outboundRules>
            <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml" enabled="true" stopProcessing="false">
                <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" />
                <action type="Rewrite" value="/foldera/folderb/{R:1}" />
                <!-- Removed condition from here -->
            </rule>
            <preConditions>
                <preCondition name="ResponseIsHtml">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    <add input="{URL}" pattern="^/foldera/folderb/.*" /> <!-- Added your condition here -->
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
    

    这种方式 Outbound Rule 将仅在 ResponseHTML 并且当前 URL 获得指定模式时应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-23
      相关资源
      最近更新 更多