压缩可以大大提高浏览网站的速度,它的原理是,在客户端请求网页后,从服务器端将网页文件压缩,再下载到客户端,由客户端的浏览器负责解压缩并浏览。
Gzip是一种流行的文件压缩算法,现在的应用十分广泛,尤其是在Linux平台。当应用Gzip压缩到一个纯文本文件时,效果是非常明显的,大约可以减少70%以上的文件大小。这取决于文件中的内容。
如果要开启gzip的话,一定要打开下面二个模块。
LoadModuleheaders_modulemodules/mod_headers.so
LoadModuledeflate_modulemodules/mod_deflate.so
检查httpd.conf以上是否存在上面两行,前面是否带“#”号;
在httpd.conf文件底部加上以下代码:
DeflateCompressionLevel6#6压缩率1-9,建议值6
AddOutputFilterDEFLATEhtmlxmlphpjscss
SetOutputFilterDEFLATE
BrowserMatch^Mozilla/4gzip-only-text/html
BrowserMatch^Mozilla/4.0[678]no-gzip
BrowserMatchbMSIE!no-gzip!gzip-only-text/html
SetEnvIfNoCaseRequest_URI\.(?:gif|jpe?g|png)$no-gzip
dont-vary
SetEnvIfNoCaseRequest_URI.(?:exe|t?gz|zip|bz2|sit|rar)$no-gzip
dont-vary
SetEnvIfNoCaseRequest_URI.(?:pdf|mov|avi|mp3|mp4|rm)$no-gzip
dont-vary
#HeaderappendVaryUser-Agentenv=!dont-vary#对代理的设置
修改后重启Apache生效!
猜你喜欢