天天看点

使用Apache模块mod_deflate加快页面打开速度

mod_deflate 模块提供了<code>deflate</code>输出过滤器,允许服务器在将输出内容发送到客户端以前进行压缩,以节约带宽。

修改httpd.conf

1.使用此模块 

loadmodule deflate_module modules/mod_deflate.so 

2.在conf文件底下加上

#deflatecompressionlevel 9    #设置压缩率

#addoutputfilterbytype deflate text/html text/plain text/xml application/x-httpd-php

#addoutputfilter deflate css js

#&lt;/ifmodule&gt;             

#以上设置,经过测试后感觉不太好,没有对css和js文件进行压缩。

&lt;location /&gt;

setoutputfilter deflate

addoutputfilterbytype deflate text/html text/plain text/xml

addoutputfilter deflate css       #压缩css文件

addoutputfilter deflate js          #压缩js文件

#browsermatch ^mozilla/4 gzip-only-text/html

#browsermatch ^mozilla/4\.0[678] no-gzip

#browsermatch \bmsie !no-gzip !gzip-only-text/html     #针对不同浏览器的配置,这里用处不大

# don't compress images                                           #对照片文件不进行压缩处理

setenvifnocase request_uri (?:gif|jpe?g|png)$ no-gzip dont-vary

setenvifnocase request_uri (?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary

setenvifnocase request_uri .pdf$ no-gzip dont-vary

#setenvifnocase request_uri .(css|js)$ no-gzip dont-vary

# make sure proxies don't deliver the wrong content

header append vary user-agent env=!dont-vary

&lt;/location&gt;

deflatefilternote input input_info                                 #设置日志输出!         

deflatefilternote output output_info

deflatefilternote ratio ratio_info

logformat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate

customlog logs/deflate_log.log deflate

 以下是日志输出 deflate_log.log :

"get /23413 http/1.1" 206/268 (76%)

"get /123 http/1.1" 205/266 (77%)

"get /favicon.ico http/1.1" 209/274 (76%)

"get / http/1.1" 75/73 (102%)

"get /new/index.jsp http/1.1" 6155/27871 (22%)

"get /new/css/index1.css http/1.1" 2028/7958 (25%)

"get /new/css/fonts.css http/1.1" 212/279 (75%)

"get /js/include.js http/1.1" 2106/5425 (38%)

"get /new/js/inc.js http/1.1" 1264/3983 (31%)

"get /search/js/search.js http/1.1" 356/730 (48%)

"get /search/js/selectarea.js http/1.1" 27757/168335 (16%)

"get /new/images/new/new_02.gif http/1.1" -/- (-%)

"get /new/images/new/new_16.gif http/1.1" -/- (-%)

"get /new/images/new/new_11.gif http/1.1" -/- (-%)

"get /new_iflogin?tt=1195799219343 http/1.1" 4/2 (200%)

"get /new/images/bian1.gif http/1.1" -/- (-%)

"get /new/js/5adpics.js http/1.1" 1068/3845 (27%)

"get /new/images/1.jpg http/1.1" -/- (-%)

"get /new/images/userimg_03.gif http/1.1" -/- (-%)

"get /new/images/4.jpg http/1.1" -/- (-%)

可以看到除了图片jpg格式文件外,其他的jsp,css,js 等都进行了压缩处理!