apache 启用 mod_deflate 发送内容编码:gzip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/878068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:37:24  来源:igfitidea点击:

Enable mod_deflate to send Content-Encoding: gzip

apachedeflatemod-deflate

提问by Sabya

EDITI have found that the problem is actually php minify. This was sending the deflated content instead of Apache. I'll find more on this.

编辑我发现问题实际上是php minify。这是发送压缩的内容而不是 Apache。我会找到更多关于这个的。

According to High Performance Web Sites, if I enable mod_deflate in Apache 2.x, by adding the following line, it should send gzipped/delfated content: -

根据高性能网站,如果我在 Apache 2.x 中启用 mod_deflate,通过添加以下行,它应该发送 gzipped/delfated 内容:-

AddOutputFilterByType DEFLATE text/html text/css application/x-javascript

The book also says that gzipis more effective than deflate.

书中还说,这gzipdeflate.

I have enabled in httpd.conf by adding the same line. But Apache sends Content-Encoding: deflate.

我通过添加同一行在 httpd.conf 中启用。但是 Apache 发送Content-Encoding: deflate.

I tested with CURL using: -

我使用 CURL 进行了测试: -

curl -i -H "Accept-Encoding: gzip" "http://192.168.1.33/s.js" >> e:\curl_log.txt

It returns 'gzipped' content. But when I send the command: -

它返回“gzip”内容。但是当我发送命令时: -

curl -i -H "Accept-Encoding: gzip, deflate" "http://192.168.1.33/s.js" >> e:\curl_log.txt

It returns 'deflated' content.

它返回“放气”的内容。

So, if the browser supports both deflated and gzipped, Apache send deflated. How to tell Apache to prefer gzip over deflate?

因此,如果浏览器同时支持 deflated 和 gzipped,Apache 将发送 deflated。如何告诉 Apache 更喜欢 gzip 而不是 deflate?

FYI: -

供参考: -

回答by voer

As I see the cause was already found. To further on help getting out of possible confusions:

如我所见,原因已经找到。为了进一步帮助摆脱可能的困惑:

  • mod_deflate despite its name is currently only supporting gzip.

  • gzip is more "effective" because of the following

  • mod_deflate 尽管其名称目前仅支持 gzip。

  • 由于以下原因,gzip 更“有效”

deflate - despite its name the zlib compression (RFC 1950) should be used (in combination with the deflate compression (RFC 1951)) as described in the RFC 2616. The implementation in the real world however seems to vary between the zlib compression and the (raw) deflate compression[3][4]. Due to this confusion, gzip has positioned itself as the more reliable default method (March 2011).

deflate - 尽管它的名字是 zlib 压缩(RFC 1950)(与 deflate 压缩(RFC 1951)结合),如 RFC 2616 中所述。然而,现实世界中的实现似乎在 zlib 压缩和(原始)放气压缩[3][4]。由于这种混淆,gzip 将自己定位为更可靠的默认方法(2011 年 3 月)。

gzip and zlib are file/stream formats that by default wrap around deflate and amongst other things add a checksum which make them more secure and a little slower. The increase in size on the other hand should not be of any concern.

gzip 和 zlib 是文件/流格式,默认情况下会环绕 deflate 并添加校验和,这使它们更安全且速度更慢。另一方面,规模的增加不应该是任何问题。

Also see HTTP_compression - Wikipedia

另请参阅HTTP_compression - 维基百科

回答by Alex Martelli

See http://httpd.apache.org/docs/2.0/mod/mod_deflate.htmlfor all the gory details -- are you sure you don't have occurrences of no-gzipelsewhere in the configuration? What happens as you vary your "browser", e.g. by using wgetwith various values for -U?

有关所有血腥细节,请参阅http://httpd.apache.org/docs/2.0/mod/mod_deflate.html- 您确定no-gzip在配置中没有其他地方出现吗?当你改变你的“浏览器”时会发生什么,例如使用wget不同的值-U

回答by SpliFF

I suspect whatever you're using to test is not sending ...

我怀疑你用来测试的任何东西都没有发送......

Accept-Encoding: gzip

接受编码:gzip

... in the request header.

...在请求标头中。