【问题标题】:Reverse proxy responding with 404 error and response URL incorrect when error反向代理响应 404 错误和错误时响应 URL 不正确
【发布时间】:2018-02-23 15:19:33
【问题描述】:

我有一个site1,它是一个 Web 客户端应用程序。 site1 调用了一些 site2 API,这些 API 遇到了 CORS 问题。

我已经在 IIS 中编写了重写规则来重写 URL 中的请求匹配字符串extFlow

来自https://site1/xyz/extFlow/Test.svc/testAPIhttps://site2/extFlow/Test.svc/testAPI

以下是我的重写规则。响应似乎写回https://site1/extFlow/Test.svc/testAPI 而不是https://site1/xyz/extFlow/Test.svc/testAPI。如果site2500 响应,则来自IIS 反向代理的最终响应为404

<rewrite> 
        <rules> 
            <rule name="Route the requests for WFL" stopProcessing="true"> 
                <match url="extFlow/(.*)" /> 
                <conditions> 
                </conditions> 
                <action type="Rewrite" url="https://site2/extFlow/{R:1}" logRewrittenUrl="true" />
                <serverVariables>
                    <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables> 
        </rules> 
        <outboundRules> 
            <rule name="ReverseProxyOutboundRule1" preCondition="NeedsResportingAcceptResp" stopProcessing="true"> 
                <match filterByTags="A" serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" /> 
                <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" /> 
            </rule> 
            <preConditions> 
                <preCondition name="NeedsResportingAcceptResp">
                    <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                </preCondition> 
            </preConditions> 
        </outboundRules> 
</rewrite>  

<handlers>
        <remove name="svc-ISAPI-4.0_64bit" />
        <remove name="svc-ISAPI-4.0_32bit" />
        <remove name="svc-Integrated-4.0" />
</handlers>

【问题讨论】:

    标签: iis url-rewriting iis-7.5


    【解决方案1】:

    也许缺少出站规则?

    <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1"> 
        <match filterByTags="None" pattern="^https://site2/extFlow($|/(.*))" /> 
        <action type="Rewrite" value="https://site1/xyz/extFlow/{R:2}" /> 
     </rule>
    

    【讨论】:

    • 我应该来这里发帖说我已经解决了这个问题.. Soory,我没有.. 我仍然接受了你的回复,因为这是我所做的:)
    • 太棒了!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 2011-03-27
    • 2019-10-23
    • 2017-07-17
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    相关资源
    最近更新 更多