簡體   English   中英

IIS 反向代理重寫編碼的 url 段(HTTP 重定向)

[英]IIS reverse proxy rewrite encoded url segement (HTTP redirect)

我使用 IIS 10 作為反向代理來托管網頁(3 方,我無法修改代碼)。

本地:本地主機:26982

外部:sub.domain.com

外部請求被重定向到本地實例。 為此,我使用以下重寫規則(web.config):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>      
        <rewrite>
            <rules>
                <clear />
                <rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}" pattern="^sub.domain.com$" />
                    </conditions>
                    <action type="Rewrite" url="http://localhost:26982/{R:1}" />
                </rule>
            </rules>
            <outboundRules>

            </outboundRules>
        </rewrite>
        <httpProtocol>
            <customHeaders>
                <remove name="X-Powered-By" />
                <add name="strict-transport-security" value="max-age=16070400" />
            </customHeaders>
        </httpProtocol>
        <security>
            <requestFiltering allowDoubleEscaping="true" />
        </security>
    </system.webServer>
</configuration>

當用戶嘗試登錄頁面時,它會重定向到 OpenID 提供程序(Steam - 使用 HTTP302 - 在標題中返回 URL)。 Unfortunately, the return url which is encoded in the path still contains http://localhost:26982 (encoded as: http%3A%2F%2Flocalhost%3A26982 ) and not http://sub.domain.com . 請求/重定向如下所示:

https://steamcommunity.com/openid/login?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Flocalhost%3A26982% 2Fsession%2Fverify&openid.realm=http%3A%2F%2Flocalhost%3A26982&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.claimed_id=http%3A%2F%2Fspecs.openid。 net%2Fauth%2F2.0%2Fidentifier_select

當我在localhost上嘗試它並且它工作正常時,這看起來是一樣的。 盡管如此,當身份驗證成功時,使用sub.domain.com時重定向不起作用,原因很明顯。

什么是正確的解碼方法 => 重寫 => 重新編碼 URL 路徑段?

如果有人對此也有問題,我找到了一個經過反復試驗的可行解決方案。

<outboundRules>
    <rule name="Rewrite Header" preCondition="IsRedirect">
        <match serverVariable="RESPONSE_Location" pattern="^https://(steamcommunity.com)/(.*)(return_to=http%3A%2F%2Flocalhost%3A26982)(.*)(realm=http%3A%2F%2Flocalhost%3A26982)(.*)" />
        <conditions>
            <add input="{R:1}" pattern="steamcommunity.com" />
        </conditions>
        <action type="Rewrite" value="https://{R:1}/{R:2}return_to=https%3A%2F%2Fsub.domain.com{R:4}realm=https%3A%2F%2Fsub.domain.com{R:6}" />
    </rule>
    <preConditions>
        <preCondition name="IsRedirect">
            <add input="{RESPONSE_STATUS}" pattern="3\d\d" />
        </preCondition>
    </preConditions>

</outboundRules>

這將使用新值重寫任何 HTTP 3XX 重定向位置。

如果有更好的解決方案,請告訴我,但現在,這對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM