mod_gzip:Apache的HTTP压缩优化
2008-05-19 15:35
381 查看
HTTP压缩对于纯文本内容可压缩至原大小的40%一下,从而提供60%以上的数据传输节约,虽然WEB服务器会因为压缩导致CPU占用的略微上升,但是可以节约大量用于传输的网络IO。对于数据压缩带来的用户浏览速度提升(让页面符合8秒定律),这点总体负载5%-10%上升是非常值得的。毕竟通过数据压缩会比通过不规范的HTML代码优化要方便得多。
mod_gzip的安装:
修改Makefile中的 apxs路径:然后make make install
配置:mod_gzip+mod_php
LoadModule gzip_module modules/mod_gzip.so
...
AddModule mod_gzip.c
...
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_minimum_file_size 1000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file /.htm$
mod_gzip_item_include file /.html$
mod_gzip_item_include file /.php$
mod_gzip_item_include file /.php3$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
# mod_gzip的临时工作目录: mkdir /tmp/mod_gzip; chmod -R 777 mod_gzip
mod_gzip_temp_dir /tmp/mod_gzip
mod_gzip_dechunk Yes
mod_gzip_keep_workfiles No
</IfModule>
mod_gzip和mod_php的配合:不要让mod_gzip和mod_php使用同一个临时目录,php_session存放目录可以通过 php.ini设置到session.save_path = /tmp/php_sess
mod_gzip和Resin配合:
从resin的邮件列表上查到的:要让mod_gzip在mod_caucho后加载,否则mod_gzip不起作用
...othr modules
AddModule mod_so.c
AddModule mod_caucho.c
#notice: mod_gzip must load after mod_caucho
AddModule mod_gzip.c
AddModule mod_expires.c
...
配置:mod_gzip + resin
<IFModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 3000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file /.html$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include handler caucho-request
</IFModule>
配置:mod_gzip + mod_proxy 反相代理加速并压缩 IIS
注意要增加缺省的文件编码属性映射。
AddType text/html .asp
AddType text/html .aspx
<IFModule mod_gzip.c>
AddType text/html .asp
AddType text/html .aspx
mod_gzip_on Yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 3000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file /.html$
mod_gzip_item_include file /.asp$
mod_gzip_item_include file /.aspx$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include handler proxy-server
</IFModule>
参考资料:
mod_gzip的下载 http://sourceforge.net/projects/mod-gzip/
mod_gzip项目首页 http://www.schroepl.net/projekte/mod_gzip/
Apache2 中的mod_deflate:压缩率比mod_gzip略低 http://httpd.apache.org/docs-2.0/mod/mod_deflate.html
模块化安装Apache
http://www.chedong.com/tech/apache_install.html
出处:http://www.chedong.com/tech/compress.html
另,相关:http://blog.sina.com.cn/s/blog_4468911c010007am.html
Mod_GZip 与 Mod_Deflate (2006-11-21 16:48:44)
Mod_GZip 是为 apache1 准备的,也有 apache2 的版本,可以设置 缓冲目录.
Mod_Deflate 是 apache2 内置的组件,更改 httpd.conf 可释放。
二个组件的压缩比率都是 10% ~ 20% 之间,可设置压缩类型,例如图片 就不需要压缩了,需注意的是要在 httpd.conf 里加一行
BrowserMatch robot no-gzip
以访止 BAIDU 这样对 Content-Encoding: gzip 视而不见的搜索引擎.
写一个规则给大家看看
LoadModule deflate_module modules/mod_deflate.so
DeflateFilterNote ratio
LogFormat '"%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" (%{ratio}n)' deflate
CustomLog logs/deflate_log deflate
<Location />
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch robot no-gzip
BrowserMatch /bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI /.(?:gif|jpe?g|png)$ no-gzip dont-vary
#Header append Vary User-Agent env=!dont-vary
</Location>
mod_gzip的安装:
修改Makefile中的 apxs路径:然后make make install
配置:mod_gzip+mod_php
LoadModule gzip_module modules/mod_gzip.so
...
AddModule mod_gzip.c
...
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_minimum_file_size 1000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file /.htm$
mod_gzip_item_include file /.html$
mod_gzip_item_include file /.php$
mod_gzip_item_include file /.php3$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
# mod_gzip的临时工作目录: mkdir /tmp/mod_gzip; chmod -R 777 mod_gzip
mod_gzip_temp_dir /tmp/mod_gzip
mod_gzip_dechunk Yes
mod_gzip_keep_workfiles No
</IfModule>
mod_gzip和mod_php的配合:不要让mod_gzip和mod_php使用同一个临时目录,php_session存放目录可以通过 php.ini设置到session.save_path = /tmp/php_sess
mod_gzip和Resin配合:
从resin的邮件列表上查到的:要让mod_gzip在mod_caucho后加载,否则mod_gzip不起作用
...othr modules
AddModule mod_so.c
AddModule mod_caucho.c
#notice: mod_gzip must load after mod_caucho
AddModule mod_gzip.c
AddModule mod_expires.c
...
配置:mod_gzip + resin
<IFModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 3000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file /.html$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include handler caucho-request
</IFModule>
配置:mod_gzip + mod_proxy 反相代理加速并压缩 IIS
注意要增加缺省的文件编码属性映射。
AddType text/html .asp
AddType text/html .aspx
<IFModule mod_gzip.c>
AddType text/html .asp
AddType text/html .aspx
mod_gzip_on Yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 3000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file /.html$
mod_gzip_item_include file /.asp$
mod_gzip_item_include file /.aspx$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include handler proxy-server
</IFModule>
参考资料:
mod_gzip的下载 http://sourceforge.net/projects/mod-gzip/
mod_gzip项目首页 http://www.schroepl.net/projekte/mod_gzip/
Apache2 中的mod_deflate:压缩率比mod_gzip略低 http://httpd.apache.org/docs-2.0/mod/mod_deflate.html
模块化安装Apache
http://www.chedong.com/tech/apache_install.html
出处:http://www.chedong.com/tech/compress.html
另,相关:http://blog.sina.com.cn/s/blog_4468911c010007am.html
Mod_GZip 与 Mod_Deflate (2006-11-21 16:48:44)
var $tag=''; |
Mod_Deflate 是 apache2 内置的组件,更改 httpd.conf 可释放。
二个组件的压缩比率都是 10% ~ 20% 之间,可设置压缩类型,例如图片 就不需要压缩了,需注意的是要在 httpd.conf 里加一行
BrowserMatch robot no-gzip
以访止 BAIDU 这样对 Content-Encoding: gzip 视而不见的搜索引擎.
写一个规则给大家看看
LoadModule deflate_module modules/mod_deflate.so
DeflateFilterNote ratio
LogFormat '"%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" (%{ratio}n)' deflate
CustomLog logs/deflate_log deflate
<Location />
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch robot no-gzip
BrowserMatch /bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI /.(?:gif|jpe?g|png)$ no-gzip dont-vary
#Header append Vary User-Agent env=!dont-vary
</Location>
相关文章推荐
- mod_gzip:Apache的HTTP压缩优化
- mod_gzip:Apache的HTTP压缩优化
- 使用Apache的mod_gzip对WEB服务器进行HTTP压缩优化
- mod_gzip:Apache的HTTP压缩优化
- Apache使用mod_deflate模块压缩页面优化传输速度
- 安装mod_deflate启用apache的GZIP压缩
- apache性能优化之启用gzip压缩
- 安装mod_deflate启用apache的GZIP压缩
- 给Tomcat,Apache配置gzip压缩(HTTP压缩)功能
- 给Tomcat,Apache配置gzip压缩(HTTP压缩)功能
- Apache配置gzip压缩(HTTP压缩)功能
- APACHE中用mod_gzip或mod_deflate开启网页传输压缩
- apache2.0x 开启gzip压缩和http缓存的配置方法
- Apache的模块mod_deflate.so开启gzip压缩功能
- Apache的优化设置&mod_deflate压缩效果分析
- apache2.0x开启gzip压缩和http缓存的配置方法
- 给Tomcat,Apache配置gzip压缩(HTTP压缩)功能 (转)
- apache 2.2.15中配置mod_deflate 页面gzip压缩
- 给Tomcat,Apache配置gzip压缩(HTTP压缩)功能
- apache2.0x 开启gzip压缩和http缓存的配置方法