【问题标题】:GZip compression in IIS7 not working, but content-encoding header is set to gzipIIS7 中的 GZip 压缩不起作用,但内容编码标头设置为 gzip
【发布时间】:2011-08-01 21:43:05
【问题描述】:

我的 IIS 7.5 启用了静态和动态压缩。它似乎适用于动态文件,但对于静态文件,它的行为不正常,当内容未压缩时,通常会发送一个 http 标头“Content-Encoding: gzip”。这会导致浏览器尝试解压缩,引发无效幻数错误。这是我的配置:

  <httpCompression dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="70" >
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
  </staticTypes>

我认为某些 http 模块正在将内容解压缩到管道的某个地方,但它们似乎都没有可疑之处。有什么想法吗?

【问题讨论】:

    标签: iis iis-7 compression http-headers gzip


    【解决方案1】:

    尝试在默认禁用的缓存之前启用动态压缩。

        <urlCompression dynamicCompressionBeforeCache="true" doDynamicCompression="true" doStaticCompression="true" />
    

    【讨论】:

    • 感谢您的建议。我尝试将该行放在 下,但没有任何区别。有什么想法吗?
    【解决方案2】:

    我在调查中发现在静态文件上使用 HttpContext.RewritePath() 会导致此问题。

    【讨论】:

    • 这很奇怪,但我认为这也是正确的,至少在我的一台 QA 服务器 (W2K8/IIS 7.5) 上是这样。
    【解决方案3】:

    我也花了一段时间才弄清楚这一点。将 applicationHost.config 文件中 system.webServer/serverRuntime 节点上的频繁HitThreshold 属性设置为 1 应该可以解决问题,如 http://www.iis.net/ConfigReference/system.webServer/serverRuntime 中所述。

    您可以通过以管理员身份执行以下命令来做到这一点:

    %windir%\system32\inetsrv\appcmd set config /section:serverRuntime /frequentHitThreshold:1 /commit:apphost
    

    一个警告 - “频繁命中”的概念似乎并不特定于压缩。不知道设置这个会不会有其他后果!

    【讨论】:

      猜你喜欢
      • 2012-09-19
      • 2012-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 2018-04-19
      相关资源
      最近更新 更多