Enable GZIP Compression error: STATIC_COMPRESSION_NOT_SUCCESS

前端 未结 3 1595
南方客
南方客 2020-12-19 14:17

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:

相关标签:
3条回答
  • 2020-12-19 15:10

    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"

    0 讨论(0)
  • 2020-12-19 15:12

    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" />
    
    0 讨论(0)
  • 2020-12-19 15:17

    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

    • How can I get gzip compression in IIS7 working?
    0 讨论(0)
提交回复
热议问题