2010-11-03 128 views
4

我試圖在IIS 7.5上啓用GZIP壓縮。啓用GZIP壓縮錯誤:STATIC_COMPRESSION_NOT_SUCCESS

我認爲所有的設置都可以。

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

下面的配置工作具體充分的權利爲了我。只需將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" overrideModeDefault="Allow" /> 

中的applicationHost.config和代替的applicationHost.config更換httpCompression部分取代

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" /> 

,下system.webServer標籤添加它在您的網站的web.config中

另外,請確保您爲數據指定了正確的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

感謝偉大的文章。爲我工作 – abzarak 2013-07-25 13:39:15

0

我建議檢查應用程序池的用戶帳戶,如果您有任何,對目錄"%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"