首页 > 解决方案 > IIS 无法重写具有 soket.io 查询的出站规则

问题描述

我正用头撞墙。每个 URL 都由 IIS URL Rewrite 模块重写,但是https://nginx-server/socket.io/?EIO=3&transport=polling&t=1486150196479-0当我在 chrome 中打开我的网络选项卡时,我看到了响应:

https://nginx-server.com/socket.io/?EIO=3&transport=polling&t=1486150196479-0
https://nginx-server.com/socket.io/?EIO=3&transport=polling&t=1486150196479-0
https://iis-reverse-proxy-server.com/t/assets/images/chat-logo.png
https://iis-reverse-proxy-server.com/config.js
https://iis-reverse-proxy-server.com/t/assets/images/main_logo.png

我正在尝试反向代理https://nginx-server. IIS 反向代理重写所有访问 nginx 的 URL,除了那些有socket.ioURI 的 URL。api当调用 some 并且 IIS 停止重写出站规则时,也会发生同样的事情。

这是我的 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="{CACHE_URL}" pattern="^(https?)://" />
                    </conditions>
                    <serverVariables>
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                    </serverVariables>
                    <action type="Rewrite" url="{C:1}://nginx-server.com/{R:0}" />
                </rule>
            </rules>
            <outboundRules>
                <clear />
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" stopProcessing="true">
                    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^(.*)?://nginx-server.com/(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" value="{R:1}://iis-reverse-proxy-server.com/{R:2}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
        <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    </system.webServer>
</configuration>

==========编辑:=========== 这是我更新的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
            
                <rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
                    <match url="^(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{CACHE_URL}" pattern="^(https?)://" />
                    </conditions>
                    <serverVariables>
                        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="HTTP_ACCEPT_ENCODING" />
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                    </serverVariables>
                    <action type="Rewrite" url="{C:1}://nginx-server.com/{R:0}" />
                </rule>
                
            </rules>
        
            <outboundRules>
            
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" stopProcessing="true">
                    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^(.*)?://nginx-server.com/(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" value="{R:1}://iis-reverse-proxy-server.com/{R:2}" />
                </rule>
            
            
           
                <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
                    <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
                    <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
                </rule>
                <rule name="Atag" preCondition="ResponseIsHtml1">
                    <match pattern="href=(.*?)https://nginx-server.com/(.*?)\s" />
                    <action type="Rewrite" value="href={R:1}https://iis-reverse-proxy-server.expertflow.com/{R:2}" />
                </rule>
                <rule name="elementencodedaction" preCondition="ResponseIsHtml1">
                    <match pattern="action=(.*?)https://nginx-server.com/(.*?)\\" />
                    <action type="Rewrite" value="‘action={R:1}https://iis-reverse-proxy-server.expertflow.com/{R:2}\" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
                    </preCondition>
                    <preCondition name="NeedsRestoringAcceptEncoding">
                        <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            
        </rewrite>
    </system.webServer>
</configuration>

我在哪里犯错?

标签: iisurl-rewritingreverse-proxynginx-reverse-proxy

解决方案


感谢大家为预期的帮助所做的努力。结果是应用程序中的配置文件重写了 URL,这就是 IIS 无法重写 URL 的原因。更新配置文件中的 URL 解决了我的问题。


推荐阅读