apache开启gzip压缩

前端之家收集整理的这篇文章主要介绍了apache开启gzip压缩前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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

 

 

猜你在找的Apache相关文章