Apache里配置 mod_expires 和 mod_headers 以支持CACHE
编译mod_expires和mod_headers
/usr/local/apache/bin/apxs -i -a -c /usr/local/httpd-2.0.54/modules/metadata/mod_expires.c
/usr/local/apache/bin/apxs -i -a -c /usr/local/httpd-2.0.54/modules/metadata/mod_headers.c
以上命令自动修改httpd.conf,激活模块
然后在 httpd.conf 里增加:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 days"
ExpiresByType text/html "access plus 1 weeks"
ExpiresByType image/gif "access plus 2 months"
ExpiresByType image/jpeg "access plus 2 months"
ExpiresByType application/x-shockwave-flash "access plus 2 months"
ExpiresByType application/x-javascript "access plus 2 months"
</IfModule>
<IfModule mod_headers.c>
# YEAR
<FilesMatch "\.(flv|gif|ico|jpeg)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# WEEK
<FilesMatch "\.(pdf|swf|js|css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
# DAY
<FilesMatch "\.(htm|html|shtml)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
</IfModule>
mod_expires 和 mod_headers 只需要其中一种就可以了。