开启Apache的mod_expires模块,在httpd.conf最后面加上以下代码(一个月后失效)。
- < IfModule mod_expires.c >
- < FilesMatch "/.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$" >
- ExpiresActive on
- ExpiresDefault "access plus 1 month"
- </ filesmatch >
- </ IfModule >
linux下安装
要支持DSO动态模块加载
安装mod_expires
cd httpd-2.2.6/modules/metadata/
/usr/local/apache/bin/apxs -c -i -a mod_expires.c
在httpd.conf中添加
ExpiresActive on
ExpiresDefault “access plus 12 month”
ExpiresByType text/html “access plus 12 months”
ExpiresByType text/css “access plus 12 months”
ExpiresByType image/gif “access plus 12 months”
ExpiresByType image/jpeg “access plus 12 months”
ExpiresByType image/jpg “access plus 12 months”
ExpiresByType image/png “access plus 12 months”
EXpiresByType application/x-shockwave-flash “access plus 12 months”
EXpiresByType application/x-javascript “access plus 12 months”
ExpiresByType video/x-flv “access plus 12 months”
windows 打开httpd.ini 找到
#LoadModule expires_module modules/mod_expires.so
取掉#号
再加上面那一段代码
重起apache,效果很明显示,apache 内存占用量下去了很多,带宽用量也少了很多~
在httpd.conf最后面加上以下代码(使用最后修改时间和文件大小作为etag)
- #This bit of code instructs Apache to send along an Etag value
- #that is calculated by combining the modification time
- #and file size of the file being transmitted.
- FileETag MTime Size