我最近在Ubuntu 16.04上将Aapche升级到了2.4.26(ondrej ppa)。 默认情况下,模块deflate和http2被启用。
在Chrome上,当服务大型JS文件时,请求不会完成,并在经过很长时间(基本上,由Apache Timeout设置指定的时间)之后通过net::ERR_CONNECTION_CLOSED失败。 在Firefox上,一切都运行完美。
我曾经尝试过
我在排除故障时观察到
小JS文件工作正常。 我有大的JS文件是259.43KB(75.78KB gzipped)
如果我在Apache中禁用HTTP2: Protocols http/1.1 ,Chrome可以正常工作。
如果我手动禁用gzip模块: a2dismod deflate ,Chrome的作品。
当然,这两个选项都不是理想的performance。
作为一个黑暗中的镜头,我试图closures这个问题的答案build议的KeepAlive : https : //stackoverflow.com/questions/25847083/chrome-just-doesnt-finish-loading-js-files 。 它不能解决问题。
我从Chrome开发者工具复制有问题的JS文件的HTTP标头:
HTTP请求头
:authority: example.com :method:GET :path:/js/main.js :scheme:https accept:*/* accept-encoding:gzip, deflate, br accept-language:en-US,en;q=0.8 cache-control:no-cache pragma:no-cache user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
HTTP响应头
accept-ranges:bytes cache-control:max-age=7200 content-encoding:gzip content-type:application/javascript; charset=utf-8 date:Mon, 03 Jul 2017 07:23:27 GMT last-modified:Thu, 01 Jun 2017 14:49:09 GMT server:Apache status:200 vary:Accept-Encoding x-content-type-options:nosniff
我做了一些阅读, 可能与缺lessContent-Length响应头的分块gzip响应有关。 也可能是由于缺lessTransfer-Encoding响应头。 但是我不确定什么是正确的事情,或者如何让Apache输出这些头文件。
问题
什么似乎是问题? 如何在我的Apache Web服务器上使用gzip启用HTTP2?
如果是由分块压缩的HTTP2响应的错误/缺失标头引起的,任何人都可以阐明哪些标头是必需的? 即什么是正确的方式来服务分块gzip HTTP2响应?
这是Apache中的一个已知错误,我目前正在处理。 请参阅https://github.com/icing/mod_h2/issues/143