1.在httpd.conf中去掉下面的#号
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so
(*apahce2.2以后deflate模块默认已经开启了,所以去掉#号会出错。)
 
2.在httpd.conf文件尾加上
# mod_deflate
<IfModule mod_deflate.c>
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 application/x-httpd-php
AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

3.重启apache服务器

 
4.修改php.ini
(*php默认不开启zlib整站压缩输出,需要压缩输出使用ob_gzhandler函数,两者只能二选一,否则会出错)
//开启压缩
zlib.output_compression = On
//设置压缩比
zlib.output_compression_level = 6
04-28 12:09