笔记 by 车东

Apache 1.3上的mod_gzip编译和配置

· 应用安装|AppInstall

最近打算做一个试验,需要重新安装一下apache 1.3上用的的http压缩模块:mod_gzip(这个模块已经很久没有维护了,apache 2.x已经内置有mod_deflate压缩模块)

以下是编译mod_gzip报的错: make APXS=/home/apache/bin/apxs

/home/apache/bin/apxs -Wc,-Wall,-O3,-fomit-frame-pointer,-pipe -c mod_gzip.c mod_gzip_debug.c mod_gzip_compress.c -o mod_gzip.so gcc -DLINUX=22 -DHAVE_SET_DUMPABLE -I/usr/include/gdbm -DUSE_HSREGEX -DUSE_EXPAT -I../lib/expat-lite -fpic -DSHARED_MODULE -I/home/apache/include -Wall,-O3,-fomit-frame-pointer,-pipe -c mod_gzip.c cc1: error: unrecognized command line option "-Wall,-O3,-fomit-frame-pointer,-pipe" apxs:Break: Command failed with rc=1 make: *** [build] Error 1

只好把Makefile中的:-Wall,-O3,-fomit-frame-pointer,这几个选项取消,然后就编译通过了…… gcc的版本如下:

Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux Thread model: posix gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)
有哪位遇到过类似问题吗?

不知道这样安装有什么影响没有,Apache已经显示为: Apache/1.3.37 (Unix) mod_perl/1.29 mod_gzip/1.3.26.1a PHP/4.4.4

压缩效果可以直接从浏览器中看到,以CheDong.com的首页为例: 压缩前(用IE,右键:看属性): 55371 字节 压缩后(用FF,右键:查看页面信息):19170 字节

IE和FF缺省都是支持HTTP压缩的,只不过IE显示的是压缩前的大小,FF显示的是压缩后的文件大小。

网页数据分析来看压缩也是生效了: 目前整个网站的流量大约有40%流量是可压缩的文本内容,启用mod_gzip后,流量大约节省了25%。

日期	参观人次	网页数	文件数	字节
2006年 十一月 01	7230	12579	67350	1.04 G字节
2006年 十一月 02	7508	13349	71861	1.04 G字节
2006年 十一月 03	7041	11772	65482	1004.74 M字节
2006年 十一月 04	5418	9347	53260	793.03 M字节
2006年 十一月 05	4724	7872	49005	691.97 M字节
2006年 十一月 06	7045	12520	69655	975.36 M字节
2006年 十一月 07	5602	10120	56570	774.63 M字节
2006年 十一月 08	6989	12756	65409	969.51 M字节
2006年 十一月 09	7091	13459	67179	1007.35 M字节
2006年 十一月 10	7033	12498	65774	979.96 M字节
**2006年 十一月 11	5116	8810	51355	707.68 M字节**
2006年 十一月 12	4826	7685	47027	551.54 M字节
2006年 十一月 13	6888	12966	69314	754.63 M字节
2006年 十一月 14	6739	13206	71077	761.50 M字节
2006年 十一月 15	6032	11448	66499	653.84 M字节
2006年 十一月 16	6414	12301	64999	657.94 M字节
2006年 十一月 17	6499	18796	70737	628.90 M字节

有了mod_gzip后我会做一个试验,比较一下各种的spider的风格,gzip可以帮助识别一些伪造Agent的spider: 因为匿名的SPIDER虽然可以伪装成MS IE,但是是很难伪装支持HTTP 1.1协议的IE的。

目前机器上的mod_gzip配置:

mod_gzip_on Yes #mod_gzip_on No mod_gzip_minimum_file_size 5000 mod_gzip_maximum_file_size 1500000 mod_gzip_maximum_inmem_size 1200000
mod_gzip_item_include file \.htm$
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.asp$
mod_gzip_item_include file \.php$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include mime ^httpd/unix-directory$
mod_gzip_item_include handler proxy-server

mod_gzip_item_exclude mime ^image/
mod_gzip_item_exclude file \.js$
mod_gzip_item_exclude file \.css$
mod_gzip_item_exclude file \.zip$
mod_gzip_item_exclude file \.gz$
mod_gzip_item_exclude file \.exe$
mod_gzip_item_exclude file \.mp3$
mod_gzip_item_exclude file \.pdf$
mod_gzip_item_exclude file \.rar$

mod_gzip_handle_methods        GET

mod_gzip_temp_dir /home/apache/mod_gzip_tmp/
mod_gzip_dechunk Yes
mod_gzip_keep_workfiles No</blockquote>

还在root的crontab中加入了清空临时文件的设置: 2 22 * * * (/usr/bin/find /home/apache/mod_gzip_tmp -mtime +0 |/usr/bin/xargs rm -f)

💬 历史评论

以下 7 条评论从旧版 Movable Type 博客迁移而来。 原始评论时间:2002–2016 年。

surain · 2006-11-18 16:13

我估计是gcc版本过高的缘故,试下用低些版本的gcc编译。


shunz · 2006-11-18 19:18

chedong的apache一直没装过mod_gzip啊,为什么不用apache 2.x?


dudu · 2006-11-19 12:03

是啊,apache2 还是挺好用的,特别是很多模块,例如mod_rewrite之类,可以很容易满足很多需求


jieer · 2006-11-20 10:33

用apache2吧,apache1.3+mod_gzip的性能不如apache2+mod_deflate,我们在测试后全部改成apache2了。


imcaptor · 2006-11-21 15:54

加这个选项会不会影响spider抓取内容?


is · 2006-11-22 00:21

和gcc版本没有啥关系把,脚本错误吧,不然就是apxs参数不对,并没有把-Wall,-O3,-fomit-frame-pointer,-pipe 这个正确的分解出来传递给gcc, 把参数分开来好了,-Wc,-Wall -Wc,-O3 ….这样. 这些参数都是优化用的,少了应该也不会有什么太多影响。


is · 2006-11-22 00:25

正确的写法应该是这样的: /home/apache/bin/apxs -Wc,"-Wall -O3 -fomit-frame-pointer -pipe" -c mod_gzip.c mod_gzip_debug.c mod_gzip_compress.c -o mod_gzip.so