首先加载两个模块
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
在httpd.conf中加入

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress p_w_picpaths
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
配置完毕打开 http://gzip.zzbaike.com/ 查看是否开启成功 压缩比例是多大
中华直销网首页打开gzip以后的压缩比例:

检测结果

是否压缩?
压缩类型:gzip
源文件大小:100.24KB
压缩后大小:20.94KB
压缩率:79.1%
 
启用前后对比图