简体   繁体   English

为什么 gzip 压缩在 IIS 8.5 上不起作用?

[英]Why is gzip compression not working on IIS 8.5?

I am unable to get gzip compression working on IIS 8.5 on a Server 2012 R2 machine.我无法在 Server 2012 R2 机器上的 IIS 8.5 上使用 gzip 压缩。 I have done some research and followed the instructions found in these posts:我做了一些研究,并按照这些帖子中的说明进行了操作:

  1. How to enable GZIP compression in IIS 7.5 如何在 IIS 7.5 中启用 GZIP 压缩
  2. Compression in IIS 8.5 not successful, stating ALREADY_CONTENT_ENCODING IIS 8.5 中的压缩不成功,说明 ALREADY_CONTENT_ENCODING
  3. GZip Compression On IIS 7.5 is not working IIS 7.5 上的 GZip 压缩不起作用
  4. gzip compression not working with IIS 8.5 gzip 压缩不适用于 IIS 8.5

Here is the relevant section of my config:这是我的配置的相关部分:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" staticCompressionIgnoreHitFrequency="true">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <!-- I have read that dynamic compression increases server CPU load.
    <dynamicTypes>
        <add mimeType="text/*" enabled="true"/>
        <add mimeType="message/*" enabled="true"/>
        <add mimeType="application/javascript" 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="*/*" enabled="false" />
    </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />

Also, in IIS, I set compression to apply to anything larger than 256 bytes.此外,在 IIS 中,我将压缩设置为适用于大于 256 字节的任何内容。 And I have performed iisreset.我已经执行了iisreset。

Nonetheless, I don't see the compression mentioned in my dev console in Chrome or IE and PageSpeed still tells me to compress stuff.尽管如此,我在 Chrome 或 IE 的开发控制台中没有看到提到的压缩,PageSpeed 仍然告诉我压缩内容。 What simple step have I missed?我错过了什么简单的步骤?

It will be difficult to understand what is happening.Assuming that you have done all the IIS settings correct.很难理解发生了什么。假设您已正确完成所有 IIS 设置。

  • For checking if compression is working fine or not,How are you accessing the website.为了检查压缩是否正常工作,您如何访问该网站。 eg If you use an FQDN www.example.com ,please try and use localhost url.例如,如果您使用 FQDN www.example.com,请尝试使用 localhost url。 This will make sure your IIS settings are correct.这将确保您的 IIS 设置正确。
  • If localhost works fine and your Fully Qualified domain name does not work,then problem can be in the network.In order for compression to work,the browser needs to send request header accept-encoding:gzip, deflate .如果 localhost 工作正常而您的完全限定域名不起作用,那么问题可能出在网络上。为了压缩工作,浏览器需要发送请求头accept-encoding:gzip, deflate many at times your proxy or load balancer can trim this header and this header may not reach the IIS server.So IIS will never compresseven if all the settings are done right.很多时候,您的代理或负载平衡器可以修剪此标头,而此标头可能无法到达 IIS 服务器。因此,即使所有设置都正确,IIS 也永远不会压缩。

To verify what is happening for the request and why IIS did not compress the request,you can do the following.要验证请求发生了什么以及 IIS 未压缩请求的原因,您可以执行以下操作。

  • make sure you have Failed Request tracing installed.确保您已安装失败请求跟踪
  • Configure your Failed Request Definition配置您的失败请求定义
    • Go to Failed Request tracing Modules转到失败请求跟踪模块
    • Click Add on the sidebar点击侧边栏的添加失败的请求跟踪
    • Enable All Content and status as 200-999启用所有内容和状态为200-999
    • And Finish the configuration.并完成配置。
    • Now reproduce the issue and you will get a traces captured in directory C:\\inetpub\\logs\\FailedReqLogFiles\\W3SVC .现在重现该问题,您将获得在目录 C:\\inetpub\\logs\\FailedReqLogFiles\\W3SVC 中捕获的跟踪。
    • Open the trace file(for each requests one file will be generated.Open the trace file in IE(make sure the request details matches the request you would like to verify) and go to the compact view打开跟踪文件(对于每个请求都会生成一个文件。在 IE 中打开跟踪文件(确保请求详细信息与您要验证的请求匹配)并转到紧凑视图失败的请求跟踪精简视图
    • Search for Compression and also check the reason搜索压缩并检查原因动态压缩失败原因

As mentioned in answers to one of the questions the OP links to, be sure to check for any anti-virus software running on the server.正如对 OP 链接到的问题之一的回答中所述,请务必检查服务器上运行的任何防病毒软件。 In my case it was ESET.就我而言,它是 ESET。 None of the IIS compression settings had an effect until the relevant ESET settings were disabled.在禁用相关 ESET 设置之前,所有 IIS 压缩设置均无效。

I'm leaving out details of the settings- I did what seemed like a pretty blanket disable and left it to IT to figure out which exact setting was most appropriate for compression to still work while retaining security.我省略了设置的详细信息 - 我做了一些看起来很全面的禁用,然后让 IT 找出哪种确切设置最适合在保持安全性的同时压缩仍然有效。

I had a similar issue and was caused by ESET with some strange behavior.我有一个类似的问题,是由 ESET 引起的,有一些奇怪的行为。 It worked on some machines but not on the one with eset, it took me some time to realize.它适用于某些机器,但不适用于带有 eset 的机器,我花了一些时间才意识到。

What happened is that ESET caused chrome to downgrade http2 requests to http 1.1 and not compress them.发生的事情是 ESET 导致 chrome 将 http2 请求降级到 http 1.1 而没有压缩它们。 It can be seen if you open network and enable 'protocol' column.如果您打开网络并启用“协议”列,则可以看到它。 After removing eset it worked even if I forced chrome to use http1.1 with '--disable-http2' flag删除 eset 后,即使我强制 chrome 使用带有“--disable-http2”标志的 http1.1,它也能工作

Anyway if it still not working I would try to (in addition to the other answers):无论如何,如果它仍然不起作用,我会尝试(除了其他答案):

  • check if different clients behave the same (in my case only dev machine had the issue)检查不同客户端的行为是否相同(在我的情况下,只有开发机器有问题)
  • deploy a simple static site (event default one) and test部署一个简单的静态站点(事件默认站点)并进行测试
  • reinstall iis重新安装 iis
  • check settings on iss server manager, configuration editor / system.webServer/httpCompression collection, change compression level检查 iss 服务器管理器上的设置,配置编辑器/system.webServer/httpCompression 集合,更改压缩级别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM