启用 GZIP 压缩错误:STATIC_COMPRESSION_NOT_SUCCESS

发布于 2024-09-30 16:11:13 字数 964 浏览 0 评论 0原文

我正在尝试在 IIS 7.5 上启用 GZIP 压缩。

我认为所有设置都没有问题。

在 ApplicationHost.config 中,我有这个 http压缩部分:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="0">
       <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
       <staticTypes>
             <add mimeType="text/*" enabled="true" />
             <add mimeType="message/*" enabled="true" />
             <add mimeType="application/x-javascript" enabled="true" />
             <add mimeType="application/atom+xml" enabled="true" />
             <add mimeType="application/xaml+xml" enabled="true" />
       </staticTypes>
</httpCompression>

和这个 url压缩部分:

<urlCompression dostaticcompression="true" />

这是失败的请求跟踪结果:

  STATIC_COMPRESSION_NOT_SUCCESS     
  Reason="UNKNOWN_ERROR"

I'm trying to enable GZIP compression on IIS 7.5.

I think all the settings are okay.

In ApplicationHost.config I have this httpCompression section:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="0">
       <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
       <staticTypes>
             <add mimeType="text/*" enabled="true" />
             <add mimeType="message/*" enabled="true" />
             <add mimeType="application/x-javascript" enabled="true" />
             <add mimeType="application/atom+xml" enabled="true" />
             <add mimeType="application/xaml+xml" enabled="true" />
       </staticTypes>
</httpCompression>

And this urlCompression section:

<urlCompression dostaticcompression="true" />

and Here is Failed Request Tracing result:

  STATIC_COMPRESSION_NOT_SUCCESS     
  Reason="UNKNOWN_ERROR"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅气称霸 2024-10-07 16:11:13

以下配置对我有用。只需将 applicationHost.config 中的 httpCompression 部分替换为下面给出的内容,然后重新启动 IIS。就是这样!!!

  <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
    staticCompressionDisableCpuUsage="95" staticCompressionEnableCpuUsage="60"
    dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="50">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
    <dynamicTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/x-javascript" enabled="true" />
      <add mimeType="*/*" enabled="false" />
      <add mimeType="application/json" enabled="true" />
      <add mimeType="application/json; charset=utf-8" enabled="true" />
    </dynamicTypes>
    <staticTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/x-javascript" enabled="true" />
      <add mimeType="application/atom+xml" enabled="true" />
      <add mimeType="application/xaml+xml" enabled="true" />
      <add mimeType="application/json" enabled="true" />
      <add mimeType="application/json; charset=utf-8" enabled="true" />
      <add mimeType="*/*" enabled="false" />
    </staticTypes>
  </httpCompression>

配置完成后,我得到了以下标头响应,这表明数据是使用 gzip 压缩进行压缩的

Cache-Control → no-cache
Content-Encoding → gzip
Content-Length → 4202
Content-Type → application/json; charset=utf-8
Date → Wed, 22 Jul 2015 07:40:17 GMT
Expires → -1
Pragma → no-cache
Vary → Accept-Encoding
X-Powered-By → ASP.NET 

。 上述配置适用于整个 IIS。如果您想为单个网站配置此选项,请在 applicationHost.config 中替换

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />

<section name="httpCompression" overrideModeDefault="Allow" />

,而不是替换 applicationHost.config 中的 httpCompression 部分,而是将其添加到您网站的 web.config 中的 system.webServer 标记下

。此外,请确保您已为您的数据指定正确的 MIME 类型。就我而言,它是 JSON 格式,所以我使用了以下配置

<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />

The below configurations worked for me. Just replace the httpCompression section in applicationHost.config with the given below and restart IIS. That's it!!!

  <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
    staticCompressionDisableCpuUsage="95" staticCompressionEnableCpuUsage="60"
    dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="50">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
    <dynamicTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/x-javascript" enabled="true" />
      <add mimeType="*/*" enabled="false" />
      <add mimeType="application/json" enabled="true" />
      <add mimeType="application/json; charset=utf-8" enabled="true" />
    </dynamicTypes>
    <staticTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/x-javascript" enabled="true" />
      <add mimeType="application/atom+xml" enabled="true" />
      <add mimeType="application/xaml+xml" enabled="true" />
      <add mimeType="application/json" enabled="true" />
      <add mimeType="application/json; charset=utf-8" enabled="true" />
      <add mimeType="*/*" enabled="false" />
    </staticTypes>
  </httpCompression>

After configuring this, I got the below Headers in response which indicates that data is compressed using gzip compression

Cache-Control → no-cache
Content-Encoding → gzip
Content-Length → 4202
Content-Type → application/json; charset=utf-8
Date → Wed, 22 Jul 2015 07:40:17 GMT
Expires → -1
Pragma → no-cache
Vary → Accept-Encoding
X-Powered-By → ASP.NET 

The above configuration is for the entire IIS. If you want to configure this for a single Website then replace

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />

with

<section name="httpCompression" overrideModeDefault="Allow" />

in applicationHost.config and instead of replacing the httpCompression section in applicationHost.config, add it under system.webServer tag in web.config of your Website

Also, make sure that you have specified correct MIME type for your data. In my case it was in JSON, so I used below configurations

<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
昔梦 2024-10-07 16:11:13

如果我查看 html5-boilerplate 项目的 web.config,他们使用此方法:

<!-- 
            GZip static file content.  Overrides the server default which only compresses static files over 2700 bytes
        -->
        <httpCompression directory="%SystemDrive%\websites\_compressed" minFileSizeForComp="1024">
            <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
            <staticTypes>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/javascript" enabled="true" />
                <add mimeType="application/json" enabled="true" />
                <add mimeType="*/*" enabled="false" />
            </staticTypes>
        </httpCompression>

https://github.com/paulirish/html5-boilerplate-server-configs/blob/ master/web.config

也许是您指定的零值,或者您正在使用的目录路径。

另请参阅

If I look at web.config of the html5-boilerplate project they use this method:

<!-- 
            GZip static file content.  Overrides the server default which only compresses static files over 2700 bytes
        -->
        <httpCompression directory="%SystemDrive%\websites\_compressed" minFileSizeForComp="1024">
            <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
            <staticTypes>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/javascript" enabled="true" />
                <add mimeType="application/json" enabled="true" />
                <add mimeType="*/*" enabled="false" />
            </staticTypes>
        </httpCompression>

https://github.com/paulirish/html5-boilerplate-server-configs/blob/master/web.config

Perhaps it's the zero value you have specified, or the directory path you are using.

See also

渔村楼浪 2024-10-07 16:11:13

我建议检查应用程序池用户帐户(如果有)是否对目录“%SystemDrive%\inetpub\temp\IIS Temporary compressed Files”具有特定的完整权限

I suggest checking that the application pool user account, if you have any, has specific full rights on the directory "%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文