为什么 nginx gzip_http_version 默认为 HTTP 1.1

pt2*_*ph8 3 nginx

gzip_http_versionnginx 的 gzip 模块中设置的默认值为HTTP 1.1。为什么?使用 gzip 和 HTTP 1.0 有什么问题吗?

Chi*_*ida 9

nginx gzip_http_version 可以有 HTTP 1.0 并且有它的警告。

When HTTP version 1.0 is used, the Vary: Accept-Encoding header is not set. As
this can lead to proxy cache corruption, consider adding it with add_header.
Also note that the Content-Length header is not set when using either version.
Keepalives will therefore be impossible with version 1.0, while for 1.1 it is
handled by chunked transfers.  
Run Code Online (Sandbox Code Playgroud)

更多信息 - http://wiki.nginx.org/HttpGzipModule

  • 第一句已从文档的较新版本中删除,因此大概它现在*确实* 仍然发送 Vary 标头。但是在 HTTP 1.0 上进行 gzip 压缩时无法使用 keep-alive(因为在输出之前无法知道内容长度)仍然存在,并且没有办法解决这个问题。所以决定哪个更糟:HTTP 1.0 客户端丢失 gzip,或 HTTP 1.0 客户端丢失 keep-alive(这对于 HTTP 1.0 上的动态脚本通常是不可能的)。 (3认同)