启用 GZIP 压缩错误:STATIC_COMPRESSION_NOT_SUCCESS [英] Enable GZIP Compression error: STATIC_COMPRESSION_NOT_SUCCESS

查看:30
本文介绍了启用 GZIP 压缩错误:STATIC_COMPRESSION_NOT_SUCCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我认为所有设置都可以.

I think all the settings are okay.

在 ApplicationHost.config 我有这个 httpCompression 部分:

In ApplicationHost.config I have this httpCompression section:

<httpCompression directory="%SystemDrive%inetpub	empIIS Temporary Compressed Files" minFileSizeForComp="0">
       <scheme name="gzip" dll="%Windir%system32inetsrvgzip.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>

还有这个 urlCompression 部分:

And this urlCompression section:

<urlCompression dostaticcompression="true" />

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

and Here is Failed Request Tracing result:

  STATIC_COMPRESSION_NOT_SUCCESS     
  Reason="UNKNOWN_ERROR"

推荐答案

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

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	empIIS Temporary Compressed Files"
    staticCompressionDisableCpuUsage="95" staticCompressionEnableCpuUsage="60"
    dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="50">
    <scheme name="gzip" dll="%Windir%system32inetsrvgzip.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 压缩进行压缩的

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 

以上配置是针对整个IIS的.如果您想为单个网站配置此功能,请替换

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" />

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

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

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

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

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" />

这篇关于启用 GZIP 压缩错误:STATIC_COMPRESSION_NOT_SUCCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆