apache mod_deflate 模块使用总结

mod_deflate 模块提供了DEFLATE 输出过滤器,允许服务器在将输出内容发送到客户端以前进行压缩,以节约带宽。具体用法请见apache2 文档

在apache2  安装时要先把mod_deflate 模块配置好,关于如何安装apache的一些模块可以参考我的这篇文章:

下面详细介绍一下这个模块的具体用法:

vi http.conf

LoadModule deflate_module modules/mod_deflate.so

#set deflate modules by 2hei
#
#DeflateCompressionLevel 9    #设置压缩率
#AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
#AddOutputFilter DEFLATE css js
#
              #以上设置,经过测试后感觉不太好,没有对css和js文件进行压缩。


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

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 等都进行了压缩处理!

你可能感兴趣的:(02),服务器优化,01),高流量高负载设计)