Thinkpad R60
RHEL 5
Apache 2.2.6
1>编译mod_deflate模块
#/usr/local/apache2/bin/apxs -i -c -a /home/sense/software/server/httpd-2.2.6/modules/filters/mod_deflate.c
apxs命令参数说明:
-i 此选项表示需要执行安装操作,以安装一个或多个动态共享对象到服务器的modules目录中。
-a 此选项自动增加一个LoadModule行到httpd.conf文件中,以激活此模块,或者,如果此行已经存在,则启用之。
-A 与 -a 选项类似,但是它增加的LoadModule命令有一个井号前缀(#),即此模块已经准备就绪但尚未启用。
-c 此选项表示需要执行编译操作。它首先会编译C源程序(.c)files为对应的目标代码文件(.o),然后连接这些目标代码和files中其余的目标代码文件(.o和.a),以生成动态共享对象dsofile 。如果没有指定 -o 选项,则此输出文件名由files中的第一个文件名推测得到,也就是默认为mod_name.so 。
#vi http.conf
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule’ lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l’) do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module modules/libphp5.so
LoadModule deflate_module modules/mod_deflate.so
#
2>配置apache使用deflate模块
设置php.ini,关闭其自身的压缩机制:
#vi /usr/local/php/lib/php.ini
=================================================
output_buffering = Off
output_handler =
zlib.output_compression = Off
=================================================
设置http.conf:
#vi /usr/local/apache2/conf/httpd.conf
=============================================================================
LoadModule php5_module modules/libphp5.so
LoadModule deflate_module modules/mod_deflate.so
#---------mod_deflate module confiugration--------------------
SetOutputFilter DEFLATE
DeflateCompressionLevel Array
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
#Explicit exclusion of files.
SetEnvIfNoCase Request_URI \.(?:gif|jpg|cab|jpe?g|exe|bmp|mp3|rar|zip|swf|png)$ no-gzip dont-vary
#Cache server support.
Header append Vary User-Agent env=!dont-vary
#logs.
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat ’"%r" %{outstream}n/%{instream}n (%{ratio}n%%)’ deflate
CustomLog logs/deflate_log deflate
#-------------------------------------------------------------
==============================================================================
3>错误处理:
# /usr/local/apache2/bin/apachectl -t
Syntax error on line 423 of /usr/local/apache2/conf/httpd.conf:
Invalid command ’Header’, perhaps misspelled or defined by a module not included in the server configuration
解决方案:安装mod_headers.c模块
/usr/local/apache2/bin/apxs -i -c -a /home/sense/software/server/httpd-2.2.6/modules/metadata/mod_headers.c
重新测试:
# /usr/local/apache2/bin/apachectl -t
httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
4>日志检测
#tail deflate_log
"GET /extmail/default/images/Sent.gif HTTP/1.1" -/- (-%)
"GET /extmail/default/images/purge.gif HTTP/1.1" -/- (-%)
"GET /extmail/cgi/netdisk.cgi?__mode=list_dir&sid=4a8fdafe221adArraydbb5711c16e6280f54 HTTP/1.1" 3247/Array114 (35%)
"GET /extmail/cgi/pref.cgi?__mode=pref_list&sid=4a8fdafe221adArraydbb5711c16e6280f54 HTTP/1.1" 3246/12568 (25%)
"GET /extmail/cgi/folders.cgi?__mode=folders_list&sid=4a8fdafe221adArraydbb5711c16e6280f54&mbmgr=1 HTTP/1.1" 3250/13053 (24%)
"GET /extmail/cgi/abook.cgi?__mode=abook_show&sid=4a8fdafe221adArraydbb5711c16e6280f54 HTTP/1.1" 30Array2/Array281 (33%)
"GET /extmail/cgi/compose.cgi?sid=4a8fdafe221adArraydbb5711c16e6280f54 HTTP/1.1" 10627/54013 (1Array%)
"GET /extmail/cgi/abook.cgi?sid=4a8fdafe221adArraydbb5711c16e6280f54&show_all=1&screen=abookac.html HTTP/1.1" 3027/Array406 (32%)
"GET /extmail/cgi/index.cgi?__mode=logout&sid=4a8fdafe221adArraydbb5711c16e6280f54 HTTP/1.1" ArrayArray7/2656 (37%)
"GET /extmail/cgi/index.cgi HTTP/1.1" 3113/Array108 (34%)