Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

iis - Enable GZIP Compression error: STATIC_COMPRESSION_NOT_SUCCESS

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

And this urlCompression section:

<urlCompression dostaticcompression="true" />

and Here is Failed Request Tracing result:

  STATIC_COMPRESSION_NOT_SUCCESS     
  Reason="UNKNOWN_ERROR"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...