Ubuntu中安装apache2默认是没开启expires模块的,但是默认开启了etag和last-modified
首先需要开启此模块:
sudo a2enmod expires
sudo service apache2 restart
然后在.htaccess文件中添加:
# enable expirations
ExpiresActive On
# expire images after a month in the client's cache
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
# HTML, css and javascript documents are good for a week from the time they were changed
ExpiresByType text/html M604800
ExpiresByType text/css M604800
ExpiresByType application/javascript M604800
开启ETag只需在.htaccess文件中添加代码:
# turn ETag on
FileETag MTime Size
Apache关掉Etag和Last-Modified的方法,可能也只有我这种无聊的人才会做这种事情.哈哈,关掉etag和last-modified会出现什么样的情况。做一个这样的测试.
不要问我这二个参数是做什么的。。。。。在我的blog中有写.
Etag关掉的方法如下,加一个none
FileETag none
要关掉Last-Modified的方法麻烦点,先想好你要去掉Last-Modified 的标签。然后用header模块来控制
LoadModule headers_module modules/mod_headers.so
<FilesMatch "\.(gif|jpg|png)">
Header unset Last-Modified
</FilesMatch>