Apache默认的http.conf配置文件中没有开启gzip压缩,apache1.3.x可以用mod_gzip进行优化网页浏览的速度,在apache2中也尝试用mod_gzip,但是配置后确发现网页不能正确显示(空白页),所以改换为mod_deflate。
下面说一下怎样在Apache2下开启gzip压缩:
- # 加载deflate模块
- LoadModule deflate_module modules/mod_deflate.so
- # 设置压缩频率,取值范围在 1(最低压缩率) 到 9(最高压缩率)之间
- # 不建议设置太高,虽然有很高的压缩率,但是占用更多的CPU资源
- DeflateCompressionLevel 3
- # Compress everything except images
- <Location />
- # 插入过滤器
- SetOutputFilter DEFLATE
- # Netscape 4.x 有一些问题...
- BrowserMatch ^Mozilla/4 gzip-only-text/html
- # Netscape 4.06-4.08 有更多的问题
- BrowserMatch ^Mozilla/4\.0[678] no-gzip
- # MSIE 会伪装成 Netscape ,但是事实上它没有问题
- BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
- # 不压缩图片
- SetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png)$ no-gzip dont-vary
- </Location>
最新评论