启用GZIP压缩错误:STATIC_COMPRESSION_NOT_SUCCESS
问题描述:
我试图在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"
答
下面的配置工作具体充分的权利为了我。只需将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" />
答
如果我看看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
也许这是你所指定的零值,或者你正在使用的目录路径。
又见
答
我建议检查应用程序池的用户帐户,如果您有任何,对目录"%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
感谢伟大的文章。为我工作 – abzarak 2013-07-25 13:39:15