启用GZIP压缩错误:STATIC_COMPRESSION_NOT_SUCCESS

4

我想在IIS 7.5上启用GZIP压缩。

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

在ApplicationHost.config文件中,我有以下httpCompression部分:

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

还有这个urlCompression部分:

<urlCompression dostaticcompression="true" />

以下是失败请求跟踪结果:

  STATIC_COMPRESSION_NOT_SUCCESS     
  Reason="UNKNOWN_ERROR"
3个回答

3
以下配置对我有用。只需将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 的。如果您想为单个网站进行配置,请替换
<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" />

0

如果我查看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

也许是您指定的零值或使用的目录路径有误。
另请参阅:

0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接