Apache开启gzip压缩 for Linux(RHEL5)

(1)首先得确认apache2是否已经加载了mod_deflate模块;
使用httpd -M 或者 /usr/local/apache2/bin/apachectl -M

如果没有mod_deflate模块,则继续下面的操作;

(2)首先找到安装之前安装的httpd-2.2.6.tar.bz2源代码gzip压缩“mod_deflate”模块,复制到apache程序目录下面(/usr/local/apache2);
定位到:cd httpd-2.2.6/modules/filters;
找到:mod_deflate.c;
cp mod_deflate.c /usr/local/apache2/modules/

(3)进入到mod_deflate.c目录,执行编译加载程序
cd /usr/local/apache2/modules/
/usr/local/apache2/bin/apxs -i -a -c mod_deflate.c

(4)重启apache2
/usr/local/apache2/bin/apachectl restart

(5)检查apache2是否已经加载了mod_deflate模块;
重启第一个步骤;

如果找到“deflate_module (shared)”就表示已经安装成功啦,继续下面的配置;

(6)编译配置文件httpd.conf,增加支持gzip的文件类型,如下:

<Location />
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/css
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 text/html
</Location>


(7)重启apache2
/usr/local/apache2/bin/apachectl restart

(8)检验是否已经开启成功。
可以到站长工具http://tool.chinaz.com/Gzips/输入网站的任一网址来测试。

或者

使用 Firefox 的 "Web Developer"组件查看;
方法:打开apache2生成出的一个页面;

在网页中单击鼠标右键 > Web Developer > 网页信息 > 查看 Response Header;

Date: Fri, 08 Jun 2012 00:31:02 GMT
Server: Apache/2.2.6 (Unix) PHP/5.2.4
X-Powered-By: PHP/5.2.4
Cache-Control: private
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 6425
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
200 OK


如果看到Content-Encoding: gzip,就表示已经完成了喽;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值