Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10806430
  • 博文数量: 2905
  • 博客积分: 20098
  • 博客等级: 上将
  • 技术积分: 36298
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-23 05:00
文章存档

2012年(1)

2011年(3)

2009年(2901)

分类: LINUX

2009-03-23 11:09:41

一、 需求
压缩apache的输出内容,降低网站带宽
二、 加载Apache的deflate模块
1、 修改apr-config
vi /usr/local/apache2/bin/apr-config
修改LDFLAGS=" " 为 LDFLAGS="-lz"
2、 到apache源安装目录下,例如
cd /root/httpd-2.0.55/modules/filters
3、加载mod_deflate模块
/usr/local/apache2/bin/apxs -i -a -c mod_deflate.c
如果没有安装headers模块,加载headers模块
cd /root/httpd-2.0.55/modules/metadata
加载mod_headers模块
/usr/local/apache2/bin/apxs -i -a –c mod_headers.c
三、配置Apache主配置文件
1. 在httpd.conf主配置文件里添加如下行
#声明输入流的byte数量
DeflateFilterNote Input instream
#声明输出流的byte数量
DeflateFilterNote Output outstream
#声明压缩的百分比
DeflateFilterNote Ratio ratio
#声明日志类型
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate_log deflate


#指定压缩参数

# 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[678] 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[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpg|cab|jpe?g|exe|bmp|mp3|rar|zip|swf|png)$ no-gzip dont-vary


# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

二、日志输出格式如下
[root@trffic2 logs]# tail -f access_log
"GET /apache_pb.gif HTTP/1.1" -/- (-%)
"GET /manual/ HTTP/1.1" 2163/7434 (29%)
"GET /manual/style/css/manual.css HTTP/1.1" 3973/18335 (21%)
"GET /manual/style/css/manual-loose-100pc.css HTTP/1.1" 1006/2882 (34%)
"GET /manual/style/css/manual-print.css HTTP/1.1" 2994/13017 (23%)
阅读(1324) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~