微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

IIS 无法重写具有 soket.io 查询的出站规则

如何解决IIS 无法重写具有 soket.io 查询的出站规则

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

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.io URI 的 URL。当调用某个 api 并且 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,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>

我哪里出错了?

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。