启用 mod_deflate 发送 Content-Encoding: gzip
编辑我发现问题实际上是php minify。 这是发送压缩的内容而不是 Apache。 我会找到更多这方面的信息。
根据 高性能网站,如果我在 Apache 2.x 中启用 mod_deflate,请添加以下行,它应该发送 gzipped/delfated 内容: -
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript
书上还说 gzip
比 deflate
更有效。
我已通过添加同一行在 httpd.conf 中启用。 但 Apache 发送 Content-Encoding: deflate
。
我使用 CURL 进行了测试: -
curl -i -H "Accept-Encoding: gzip" "http://192.168.1.33/s.js" >> e:\curl_log.txt
它返回“gzipped”内容。 但是当我发送命令时: -
curl -i -H "Accept-Encoding: gzip, deflate" "http://192.168.1.33/s.js" >> e:\curl_log.txt
它返回“压缩”内容。
因此,如果浏览器同时支持 deflated 和 gzipped,Apache 会发送 deflated。 如何告诉 Apache 更喜欢 gzip 而不是 deflate?
仅供参考:-
- 我在以下位置找不到任何内容: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html 。
- 没有出现 no-gzip 阿帕奇会议
- 服务器:Apache/2.2.9 (Win32) PHP/5.2.6
- FF 发送请求标头为:“Accept-Encoding: gzip, deflate”
EDIT I have found that the problem is actually php minify. This was sending the deflated content instead of Apache. I'll find more on this.
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: -
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript
The book also says that gzip
is more effective than deflate
.
I have enabled in httpd.conf by adding the same line. But Apache sends Content-Encoding: deflate
.
I tested with CURL using: -
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: -
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?
FYI: -
- I could not find anything in:
http://httpd.apache.org/docs/2.0/mod/mod_deflate.html. - There is no occurrence of no-gzip in
the Apache conf. - Server: Apache/2.2.9 (Win32) PHP/5.2.6
- FF sends request header as: "Accept-Encoding: gzip, deflate"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,原因已经找到了。 为了进一步帮助摆脱可能的混乱:
mod_deflate 尽管其名称目前仅支持 gzip。
gzip 更“有效”,因为以下原因
gzip 和 zlib 是文件/流格式,默认情况下环绕 deflate,并添加校验和,这使它们更安全且速度稍慢。 另一方面,尺寸的增加不应引起任何关注。
另请参阅 HTTP_compression - Wikipedia
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
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.
Also see HTTP_compression - Wikipedia
请参阅 http://httpd.apache.org/docs/2.0/mod/mod_deflate .html 了解所有血淋淋的细节——您确定在配置中的其他地方没有出现
no-gzip
吗? 当您改变“浏览器”时会发生什么,例如使用wget
以及不同的-U
值?See http://httpd.apache.org/docs/2.0/mod/mod_deflate.html for all the gory details -- are you sure you don't have occurrences of
no-gzip
elsewhere in the configuration? What happens as you vary your "browser", e.g. by usingwget
with various values for-U
?我怀疑您用来测试的任何内容都没有
发送 ... Accept-Encoding: gzip ... 。
在请求标头中
I suspect whatever you're using to test is not sending ...
Accept-Encoding: gzip
... in the request header.