centos5.8 64 php5.3.15 apache2.2.22
apache2.2.22源码编译安装目录 /home/software/apache/httpd-2.2.22/
apache2.2.22安装目录 /usr/local/apache/
mod_expires 用于发送header,设置静态文件的过期时间
cd  /home/software/apache/httpd-2.2.22/modules/metadata
/usr/local/apache/bin/apxs -i -a -c mod_expires.c
vi /usr/local/apache/conf/httpd.conf
<IfModule expires_module>
ExpiresActive On
ExpiresDefault A600
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
</IfModule>
A2592000表示gif的有效期为一个月
mod_deflate 用于开启gzip压缩
cd  /home/software/apache/httpd-2.2.22/modules/filters
/usr/local/apache/bin/apxs -i -a -c mod_deflate.c
vi /usr/local/apache/conf/httpd.conf
<IfModule deflate_module>
    SetOutputFilter DEFLATE
    DeflateCompressionLevel 9
    # Netscape 4.x 有一些问题…
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    # Netscape 4.06-4.08 有更多的问题
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # MSIE 会伪装成 Netscape ,但是事实上它没有问题
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    # 确保代理不会发送错误的内容
    Header append Vary User-Agent env=!dont-vary
    # Don’t compress images and other 不压缩图片
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

[root@web1 filters]# service httpd restart
httpd: Syntax error on line 345 of /usr/local/apache/conf/httpd.conf: module deflate_module is built-in and can’t be loaded

如果出现以上错误,请注释掉该模块,编译安装的时候已经内置支持了。