URL 重写模块错误。 HTTP 错误 500.52

问题描述 投票:0回答:1

所以我面对这个问题已经有一段时间了,并尝试了多种可能的解决方案,但似乎没有一个对我有用。我不断收到 gzip 错误。所以我的后端应用程序在 Tomcat(Tomee) 上运行。

以下是我的入站规则

        <rule name="ApplicationInbound" enabled="true">
            <match url="(.*)" />
            <action type="Rewrite" url="https://Application:543/{R:0}" />
            <serverVariables>
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
            </serverVariables>
        </rule>

出境:

        <rule name="ApplicationOutbound" preCondition="NeedsRestoringAcceptEncoding" enabled="false">
            <match filterByTags="None" pattern="http(s)?://App\.domain\.local:543/(.*)" />
            <action type="Rewrite" value="https://Public:543/{R:0}" />
        </rule>

前提条件

<preCondition name="NeedsRestoringAcceptEncoding">
   <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
<preCondition name="NeedsRestoringAcceptEncoding">
   <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>

提前致谢

其他信息

  1. 当我禁用出站规则时,应用程序会加载
  2. 我已经做了注册表项
    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v LogRewrittenUrlEnabled /t REG_DWORD /d 0
  3. 这是我的模块的顺序 Modules order
iis url-rewrite-module
1个回答
0
投票

当 HTTP 响应的内容经过编码(“gzip”)时,无法应用出站重写规则。状态代码为 500.52。

这是因为来自后端服务器的响应正在使用 HTTP 压缩,并且 URL 重写无法修改已压缩的响应。这会导致出站规则处理错误,从而导致 500.52 状态代码。

有两种方法可以解决此问题:

  1. 关闭传送 HTTP 响应的后端服务器上的压缩(这可能会也可能不会,具体取决于您的配置)。

  2. 尝试通过在请求进入 IIS 反向代理时删除标头并在响应离开 IIS 服务器时放回标头来向后端服务器指示客户端不接受压缩响应。

对于第二种方法,我们需要添加两个名为 HTTP_ACCEPT_ENCODING 和 HTTP_X_ORIGINAL_ACCEPT_ENCODING 的变量。我们需要在入站规则中使用这些变量来删除 Accept-Encoding 标头,并在出站规则中使用这些变量来重新放回该标头。

您可以尝试在 web.config 中使用以下重写规则:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ApplicationInbound" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="https://App.domain.local:543/{R:1}" />
                    <serverVariables>
                        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                    </serverVariables>
                </rule>
            </rules>
            <outboundRules>
                <rule name="ApplicationOutbound" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^https://App\.domain\.local:543/(.*)" />
                    <action type="Rewrite" value="https://Public:543/{R:1}" />
                </rule>
                <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
                    <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
                    <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                    <preCondition name="NeedsRestoringAcceptEncoding">
                        <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

更多信息可以参考这个链接:

https://techcommunity.microsoft.com/t5/iis-support-blog/iis-acting-as-reverse-proxy-where-the-problems-start/ba-p/846259

© www.soinside.com 2019 - 2024. All rights reserved.