【问题标题】:Enable GZIP Compression error: STATIC_COMPRESSION_NOT_SUCCESS启用 GZIP 压缩错误:STATIC_COMPRESSION_NOT_SUCCESS
【发布时间】:2011-05-04 17:47:21
【问题描述】:

我正在尝试在 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"

【问题讨论】:

    标签: iis iis-7 compression gzip


    【解决方案1】:

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

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

    另见

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案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 中,而不是替换 applicationHost.config 中的 httpCompression 部分,将其添加到您网站的 web.config 中的 system.webServer 标记下

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

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

        【讨论】:

          猜你喜欢
          • 2013-12-29
          • 2014-01-06
          • 2013-05-05
          • 2011-10-11
          • 1970-01-01
          • 2011-02-28
          • 2020-11-11
          • 1970-01-01
          • 2012-09-21
          相关资源
          最近更新 更多