1、作用
节约带宽,额外消耗CPU;部分老浏览器不支持;
压缩适于压缩的资源,例如文本文件;
2、涉及模块
LoadModule deflate_module modules/mod_deflate.so(CentOS6默认启用)
3、配置(httpd-2.2)
~]# vim /etc/httpd/conf.d/mod_deflate.conf
输入以下代码
SetOutputFilter DEFLATE # 设置压缩过滤器,指明哪些类型适合压缩 # mod_deflate configuration # Restrict compression to these MIME types AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/css # Level of compression(Highest 9 - Lowest 1) DeflateCompressionLevel 6 # 压缩级别根据CPU消耗和带宽来决定,6为默认 # 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
~]# httpd -t
~]# service httpd reload
4、确认压缩效果
配置前
配置后
本文出自 “kim1220” 博客,请务必保留此出处http://228984.blog.51cto.com/218984/1765740
原文地址:http://228984.blog.51cto.com/218984/1765740