云服务器知识

CentOS6下Apache开启Gzip网页压缩功能

  

1、进入/etc/httpd/conf下打开httpd.conf文件

开启Gzip压缩功能,即去掉LoadModule deflate_module modules/mod_deflate.so这行前面的#号,默认已经去掉。

2、进行Gzip压缩设置,添加:

# mod_deflate:DeflateCompressionLevel 6AddOutputFilterByType 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

其中DeflateCompressionLevel 6为压缩率,取值1-9之间,默认为6.

3、重启apache

service httpd restart

4、如果网站使用的是CodeIgniter框架,需要在config文件中进行设置,将

$config['compress_output'] = FALSE;

改为:

$config['compress_output'] = TRUE;