Apache deflate模块配置说明

一、 需求
压缩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 �Cc 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


#指定压缩参数
<Location />
# 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
</Location>
二、日志输出格式如下
[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%)

你可能感兴趣的:(apache,linux,职场,休闲,linux总结)