【转】Apache mod_expires mod_deflate模块DSO动态安装

安装mod_expires
mod_expires模块添加是启用对有效期控制,也可以加里面,有效控制带宽成本
#cd /usr/local/src/httpd-2.2.17/modules/metadata
#apxs -c -i -a mod_expires.c
输出
[root@web-02 metadata]# apxs -c -i -a mod_expires.c
/usr/local/apache/build/libtool --silent --mode=compile gcc -prefer-pic   -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache/include  -I/usr/local/apache/include   -I/usr/local/apache/include   -c -o mod_expires.lo mod_expires.c && touch mod_expires.slo
/usr/local/apache/build/libtool --silent --mode=link gcc -o mod_expires.la  -rpath /usr/local/apache/modules -module -avoid-version    mod_expires.lo
/usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/local/apache/build/libtool' mod_expires.la /usr/local/apache/modules
/usr/local/apache/build/libtool --mode=install cp mod_expires.la /usr/local/apache/modules/
cp .libs/mod_expires.so /usr/local/apache/modules/mod_expires.so
cp .libs/mod_expires.lai /usr/local/apache/modules/mod_expires.la
cp .libs/mod_expires.a /usr/local/apache/modules/mod_expires.a
chmod 644 /usr/local/apache/modules/mod_expires.a
ranlib /usr/local/apache/modules/mod_expires.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apache/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache/modules/mod_expires.so
在httpd.conf里添加即可
ExpiresActive on
ExpiresDefault "access plus 14 month"
ExpiresByType text/html "access plus 14 months"
ExpiresByType text/css "access plus 14 months"
ExpiresByType image/gif "access plus 14 months"
ExpiresByType image/jpeg "access plus 14 months"
ExpiresByType image/jpg "access plus 14 months"
ExpiresByType image/png "access plus 14 months"
EXpiresByType application/x-javascript "access plus 14 months"
验证
[root@web-02 metadata]#  ll /usr/local/apache/modules/
total 21788
-rw-r--r-- 1 root root     9106 Mar 20 13:43 httpd.exp
-rwxr-xr-x 1 root root 21998563 Mar 20 14:14 libphp5.so
-rwxr-xr-x 1 root root    58234 Mar 24 20:54 mod_deflate.so
-rwxr-xr-x 1 root root    36265 Mar 30 17:24 mod_expires.so
-rwxr-xr-x 1 root root   162527 Mar 20 13:44 mod_rewrite.so
mod_deflate 模块提供了DEFLATE 输出过滤器,允许服务器在将输出内容发送到客户端以前进行压缩,以节约带宽。
安装过程
#/usr/local/src/httpd-2.2.17/modules/filters
#apxs -i -c -a mod_deflate.c
输出
[root@WEB-02 filters]# apxs -c -i -a mod_deflate.c
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic   -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/local/apache/include  -I/usr/include/apr-1   -I/usr/include/apr-1   -c -o mod_deflate.lo mod_deflate.c && touch mod_deflate.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_deflate.la  -rpath /usr/local/apache/modules -module -avoid-version    mod_deflate.lo
/usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' mod_deflate.la /usr/local/apache/modules
/usr/lib64/apr-1/build/libtool --mode=install cp mod_deflate.la /usr/local/apache/modules/
cp .libs/mod_deflate.so /usr/local/apache/modules/mod_deflate.so
cp .libs/mod_deflate.lai /usr/local/apache/modules/mod_deflate.la
cp .libs/mod_deflate.a /usr/local/apache/modules/mod_deflate.a
chmod 644 /usr/local/apache/modules/mod_deflate.a
ranlib /usr/local/apache/modules/mod_deflate.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apache/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache/modules/mod_deflate.so
[activating module `deflate' in /usr/local/apache/conf/httpd.conf]
验证:
[root@WEB-02 filters]# ll /usr/local/apache/modules/
total 21352
-rw-r--r-- 1 root root     9106 Mar  8 20:29 httpd.exp
-rwxr-xr-x 1 root root 21704334 Mar  8 20:38 libphp5.so
-rwxr-xr-x 1 root root    32479 Mar 30 17:34 mod_deflate.so
-rwxr-xr-x 1 root root    81566 Mar  8 20:29 mod_rewrite.so
正确安装后,修改httpd.conf添加下面的内容即可
<IfModule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType   DEFLATE text/plain application/x-httpd-php
AddOutputFilter         DEFLATE  php  css  js
</IfModule>
PS:
apxs参数
-i 此选项表示需要执行安装操作,以安装一个或多个动态共享对象到服务器的modules目录中。
-a 此选项自动增加一个LoadModule行到httpd.conf文件中,以激活此模块,或者,如果此行已经存在,则启用之。
-A 与 -a 选项类似,但是它增加的LoadModule命令有一个井号前缀(#),即此模块已经准备就绪但尚未启用。
-c 此选项表示需要执行编译操作。它首先会编译C源程序(.c)files为对应的目标代码文件(.o),然后连接这些目标代码和files中其余的目标代码 文件(.o和.a),以生成动态共享对象dsofile 。如果没有指定 -o 选项,则此输出文件名由files中的第一个文件名推测得到,也就是默认为mod_name.so 。
PS:安装此模块后,一定要检查下配置文件语法
# apachectl -t
如果出现这样的错误
httpd: Syntax error on line 58 of /opt/apache/conf/httpd.conf: Cannot load /opt/apache/modules/mod_deflate.so into server: /opt/apache/modules/mod_deflate.so: undefined symbol: inflateEnd
解决办法有二
办法1
需要在 LoadModule deflate_module  modules/mod_deflate.so 的前面加载zlib.so

a.32操作系统增加以下内容:
LoadFile /usr/lib/libz.so
LoadModule deflate_module     modules/mod_deflate.so

b.64操作系统增加以下内容:
LoadFile /usr/lib64/libz.so
LoadModule deflate_module     modules/mod_deflate.so 
办法2
vi /usr/local/apache2/bin/apr-config
修改LDFLAGS=" " 为 LDFLAGS="-lz"
然后再apxs -i -c -a mod_deflate.c 


使用mod_gzip 和 mod_deflate对网页内容进行压缩的参考文章:
http://sheriy.com/2011/05/13/linux-server-gzip-file-compression-method/

你可能感兴趣的:(apache)