Apache-2.4------------ 启用Gzip压缩的方法(apache中虚拟主机配置优先生效)
1、开启模块mod_deflate和mod_filter
2、httpd.conf末尾添加以下内容
vi /etc/httpd/conf/httpd.conf
<IfModule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js
</IfModule>
3、重启apache
[root@Oldboy extra]# /application/apache/bin/apachectl -t
Syntax OK
[root@Oldboy extra]# /application/apache/bin/apachectl restart
4、测试是否开启gzip
(1) 使用curl查看是否开启gzip
[root@Oldboy ~]# curl -I -H "Accept-Encoding: gzip,deflate" http://bbs.etiantian.org
HTTP/1.1 200 OK
Date: Tue, 05 Jul 2016 03:25:58 GMT
Server: Apache/2.2.31 (Unix) DAV/2 PHP/5.5.32
Last-Modified: Mon, 04 Jul 2016 21:23:19 GMT
ETag: "60363-b-536d5f1f7cc62"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip 表示开启gzip
Content-Length: 31
Content-Type: text/html
(2) 使用wget查看文件大小
[root@Oldboy ~]# wget --spider http://mobile.yingyou360.cn/lingzhu/huajianghuzhilingzhu_1.2.5.apk
开启 Spider 模式。检查是否存在远程文件。
--2016-05-24 11:22:01-- http://mobile.yingyou360.cn/lingzhu/huajianghuzhilingzhu_1.2.5.apk
正在解析主机 mobile.yingyou360.cn... 114.112.100.245
正在连接 mobile.yingyou360.cn|114.112.100.245|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:246915507 (235M) [application/vnd.android.package-archive]
存在远程文件。
Apache-2.2--------------- 启用Gzip压缩的方法
1、加入“LoadModule deflate_module modules/mod_deflate.so”这行
2、 添加配置项目(在httpd.conf末尾)
vi /etc/httpd/conf/httpd.conf
<IfModule mod_deflate.c>
# 压缩等级 9
DeflateCompressionLevel 9
# 压缩类型 html、xml、php、css、js
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascript application/x-httpd-php
AddOutputFilter DEFLATE js css
</IfModule>
3、重启apache
[root@Oldboy extra]# /application/apache/bin/apachectl -t
Syntax OK
[root@Oldboy extra]# /application/apache/bin/apachectl restart
4、测试
(1) 使用curl查看是否开启gzip
[root@Oldboy ~]# curl -I -H "Accept-Encoding: gzip,deflate" http://bbs.etiantian.org
(2) 使用wget查看文件大小
[root@Oldboy ~]# wget --spider http://mobile.yingyou360.cn/lingzhu/huajianghuzhilingzhu_1.2.5.apk