Apache使用mod_deflate模块启用gzip功能

Apache使用mod_deflate模块启用gzip功能

检查你的网站是否启用了gzip,用chrome打开网站比如http://www.techbrood.com

选中一个请求,查看Response header部分,如果没有包含

Content-Encoding:
gzip

那么你还没有开启gzip网页压缩功能。

1.首先检查是否已安装mod_deflate:
# /usr/local/apache2/bin/apachectl -t -D DUMP_MODULES
Loaded Modules:
...
deflate_module (static)
...
Syntax OK

如果没有deflate模块,则需要重新编译apache2.
首先查看你apache2安装路径build目录下的config.nice文件,其中有原来的configure(编译选项)
然后添加 ./configure ...... --enable-deflate,重新make && make install。重启apache。

2.在配置中开启gzip
在httpd配置文件中添加如下语句(注意,这里使用了apache2里面的mod_deflate而不是1.3里面的mod_gzip):
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <IfModule mod_mime.c>  
  2.  AddType application/x-javascript .js  
  3.  AddType text/css .css  
  4. </IfModule>  
  5. <IfModule mod_deflate.c>  
  6.  AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript  
  7.  <IfModule mod_setenvif.c>  
  8.   BrowserMatch ^Mozilla/4 gzip-only-text/html  
  9.   BrowserMatch ^Mozilla/4\.0[678] no-gzip  
  10.   BrowserMatch \bMSIE !no-gzip !gzip-only-text/html  
  11.  </IfModule>  
  12.  <IfModule mod_headers.c>  
  13.   Header append Vary User-Agent env=!dont-vary  
  14.  </IfModule>  
  15. </IfModule>  

然后重启apache:
service restart httpd

再用浏览器发送一个请求,查看Response header部分,如配置正确,应该如下所示:


通过gzip,通常可以把文本文件(如html/js/css)大小压缩到1/3到1/5左右,无疑会大大提高网站性能。

另外一个直观的方法是看请求返回文件大小和内容,如下图肯定是被压缩过了:

转自:http://blog.csdn.net/iefreer/article/details/22766025
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值