mod_deflate - 大多数浏览器的最佳配置

Jas*_*ley 8 proxy mod-proxy virtualhost mod-deflate apache-2.2

我想知道这里是否有人可以帮助我确定在 Apache 中使用 mod deflate 的最佳标准配置。基本上,mod_deflate 建议使用以下配置立即开始:

仅压缩几种类型

AddOutputFilterByType DEFLATE text/html text/plain text/xml http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

但是,仅通过阅读文档,您就可以为所有浏览器自定义它。此外,您可以为所有不同类型的 mime 类型自定义 mod_deflate。我想知道是否有人尝试过这些设置并找到了对所有浏览器都最佳的设置。

Apache 提供的另一个示例,但如果您不了解所有配置选项,请不要使用:

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
Run Code Online (Sandbox Code Playgroud)

http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

我了解大多数配置设置,我想设置类似的东西。我不介意避免压缩已经压缩的图像和其他媒体。我有问题的细节是了解它如何与所有不同的浏览器,chrome,firefox,IE,Opera 等做出反应......显然我不关心 Netscape 4.X。我希望有人已经测试了所有这些,并且可能能够推荐符合此标准的良好设置。

我的意思是,如果这只是使用文档中推荐的设置的问题,我可以接受,但我想检查一下以确定。

只是提供一些额外的细节。我们使用 Apache 作为我们所有网络服务的前端。例如:confluence、git、gitweb 等...

Tomcat 和其他服务是通过 Apache 代理的,所以我们有虚拟主机、mod_proxy w/AJP、mod_ssl 的配置。

我的公司没有专门的 IT 团队,因此我必须在业余时间进行大部分设置。我将不胜感激您能提供的任何意见。

所以只是为了清楚地说明我在问什么,处理从 Apache 到主流浏览器的请求的基本内容需求的最佳配置是什么?

到目前为止,我的基本内容类型列表:

  • 文本/html
  • 文本/普通
  • 文本/xml
  • 文本/x-js
  • 文本/javascript
  • 文本/CSS
  • 应用程序/xml
  • 应用程序/xhtml+xml
  • 应用程序/x-javascript
  • 应用程序/javascript
  • 应用程序/json

显然不需要压缩的类型:

  • 图像 - gif、jpg、png
  • 档案 - exe、gz、zip、sit、rar

Jas*_*ley 8

我继续研究了这个。在阅读了多个教程和 Apache 文档后,我能够拼凑出一些实质性的东西,这似乎运作良好。使用上面的列表,我整理了一组规则/声明,它们似乎可以处理主流内容类型的压缩:

<Location />
# Insert filter
SetOutputFilter DEFLATE

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css 
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/x-javascript application/javascript
AddOutputFilterByType DEFLATE application/json

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI \
    \.(?:exe|t?gz|zip|bz2|sit|rar)$ \
    no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

</Location>
Run Code Online (Sandbox Code Playgroud)

为了测试,我基本上使用了 Firefox 的 TamperData 并打开了 apache 的 deflate 日志记录:

https://addons.mozilla.org/en-US/firefox/addon/tamper-data/

对于 Apache,添加以下内容:

# For Testing Purposes
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

#LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate_log deflate
Run Code Online (Sandbox Code Playgroud)

http://httpd.apache.org/docs/2.0/mod/mod_deflate.html#deflatefilternote

  • 我认为我什至不会担心那些古老的浏览器,但除此之外,这是一篇出色的文章。 (3认同)
  • `SetOutputFilter DEFLATE` 为所有内容启用压缩,因此不需要你的 `AddOutputFilterByType` 指令。 (2认同)