Apache deflate模块配置说明 前几天一直在找apache2.0以dso方式编译后加载deflate模块的办法 试了apxs -ica mod_deflate.cN次,始终是报 Cannot load /opt/apache/modules/mod_deflate.so into server: /opt/apache/modules/mod_deflate.so: undefined symbol: deflate 异常的痛苦,什么ldd mod_deflate.so后再export LIB_LIBRARY_PATH呀,都试了N次,google也go了N天。终于在google上go出来一篇文章,终于解决,方法如下: vi /usr/local/apache2/bin/apr-config 修改LDFLAGS= 为 LDFLAGS=-lz 然后再apxs -ica mod_deflate.c 就OK了
另外在配置deflate规则时 apache2.0推荐加上这句 Header append Vary User-Agent env=!dont-vary 以便确保不会输出在压缩过程中出现内容方面的error 但一般情况下,在测试apache的语法过程中会现出 Invalid command 'Header', perhaps mis-spelled or defined by a module not included in the server configuration 解决办法就是加载一个headers模块就OK了
不过最好还是在编译apache模块时直接加上--enable-deflate --enable-headers就省事多了。
一、 需求 压缩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
#指定压缩参数 <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%) 原文:http://www.ceass.com/index.php?play=reply&id=90 本文转摘自『IT学习者』http://www.itlearner.com/article/2007/3819.shtml
|