检查你的网站是否启用了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。
或者使用apxs:
1. 查找模块deflate
find your_httpd2_download_folder -name mod_deflate.c
cd your_httpd2_download_folder/modules/filters
2. 安装mod_deflate
/usr/local/apache2/bin/apxs -i -c -a mod_deflate.c
3. 配置mod_deflate
vi /usr/local/apache2/conf/httpd.conf
LoadModule deflate_module modules/mod_deflate.so
2.在配置中开启gzip
在httpd配置文件中添加如下语句(注意,这里使用了apache2里面的mod_deflate而不是1.3里面的mod_gzip):
AddType application/x-javascript .js
AddType text/css .css
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
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary
如果要对某个特定类型的文件进行压缩,可以先AddType text/svg .svg, 然后把text/svg添加到AddOutputFilterByType列表中.
最后重启apache:
service httpd restart
即可生效。