天天看點

使用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 等都進行了壓縮處理!