网站建设
Apache开启GZIP压缩功能
Apache支持GZIP压缩的配置
1、编辑 http.conf 文件,开启mod_deflate模块
去掉 #LoadModule headers_module modules/mod_headers.so 前面的注释#
去掉 #LoadModule deflate_module modules/mod_deflate.so 前面的注释#
去掉 #LoadModule filter_module modules/mod_filter.so 前面的注释#
2、配置Gzip压缩相关参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<IfModule mod_deflate.c> #压缩率,6是建议值。 DeflateCompressionLevel 6 AddOutputFilterByType DEFLATE text /plain AddOutputFilterByType DEFLATE text /html AddOutputFilterByType DEFLATE text /xml AddOutputFilterByType DEFLATE text /css AddOutputFilterByType DEFLATE text /javascript AddOutputFilterByType DEFLATE application /xhtml +xml AddOutputFilterByType DEFLATE application /xml AddOutputFilterByType DEFLATE application /rss +xml AddOutputFilterByType DEFLATE application /atom_xml AddOutputFilterByType DEFLATE application /x-javascript AddOutputFilterByType DEFLATE image /svg +xml AddOutputFilterByType DEFLATE image /gif image /png image /jpe image /swf image /jpeg image /bmp #排除不需要压缩的文件 BrowserMatch ^Mozilla /4 gzip -only-text /html BrowserMatch ^Mozilla /4 .0[678] no- gzip BrowserMatch bMSIE !no- gzip ! gzip -only-text /html SetEnvIfNoCase Request_URI .(?:html|htm)$ no- gzip dont-varySetEnvIfNoCase SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no- gzip dont-vary SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no- gzip dont-vary < /IfModule > |
3、重启Apache服务器并且使用浏览器请求验证是否Gzip生效。