Apache 开启 GZip 压缩
我这里用的是 xampp1.7.0打开xampp\apache\conf\httpd.conf文件
搜索 deflate_module modules/mod_deflate.so
把LoadModule deflate_module modules/mod_deflate.so 前面的#号给去掉 , 注意 不要在deflate.so后面加#remark info , 会不能启动 apache
在httpd.conf文件的最后 , 加入如下代码 :
# 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 no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI !no-gzip !gzip-only-text/html
# Don't compress images
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
重启apache即可启动 gzip 压缩 。
测试 : 访问本机的localhost/test/gzip.php 页面 , 用火狐浏览器的 freebug 查看请求 url 的返回信息 , 在"响应头信息"里有Content-Encoding : gzipdeflate 表明已经成功启用 GZIP 压缩 , 我的这个测试页面600b 左右 , 压缩后是470b 左右
关于apache gzip 的其他信息 : http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
页:
[1]