ubuntu apache mod_expires模块

ubuntu 下mod_expires是安装好的,开启就可以了

sudo a2enmod headers
sudo a2enmod expires
sudo /etc/init.d/apache2 restart

在httpd.conf中添加

<IfModule mod_expires.c>
# turn on the module for this directory
ExpiresActive on

# cache common graphics for 3 days
ExpiresByType image/jpg "access plus 3 days"
ExpiresByType image/gif "access plus 3 days"
ExpiresByType image/jpeg "access plus 3 days"
ExpiresByType image/png "access plus 3 days"

# cache CSS for 24 hours
ExpiresByType text/css "access plus 24 hours"

# set the default to 24 hours
ExpiresDefault "access plus 24 hours"
</IfModule>

All that was left was to restart Apache and test everything.

/<your path>/apache2/bin/apachectl configtest
/<your path>/apache2/bin/apachectl restart

Testing was simple. I tailed the access log and made two requests for the same page. The first request resulted with a flurry of files being requested (all the graphics being downloaded). The second request resulted in a single file request (no graphics) and the graphics where logged as HTTP status 304 (unmodified), success.

 

apache中如果需要关闭不用的模块,则使用 a2dismod 命令

 重新加载配置文件:

root@ubuntu:~# sudo /etc/init.d/apache2 force-reload

 

參考:

http://www.electrictoolbox.com/apache-mod-expires-browser-caching/

http://blog.csdn.net/fafa211/article/details/5515457

http://www.360doc.com/content/08/0626/16/36491_1373009.shtml

http://blog.chedushi.com/archives/3868

http://www.geekwisdom.com/dyn/cache-control2

 

posted @ 2012-09-10 12:31  feiling  阅读(495)  评论(0编辑  收藏  举报