2312123www 发表于 2016-5-26 10:56:44

apache配置静态缓存

1、打开虚拟主机配置文件
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
2、添加以下模块
在此段CustomLog "|usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combined env=!image-request插入以下模块:
<IfModule mod_expires.c>
       ExpiresActive on
       ExpiresByType image/gif "access plus 1 days"
       ExpiresByType image/jpeg "access plus 24 hours"
       ExpiresByType image/png "access plus 24 hours"
       ExpiresByType text/css "new plus 2 hours"
       ExpiresByType application/x-javascript "now plus 2 hours"
       ExpiresByType application/x-shockwave-flash "now plus 2 hours"
       ExpiresDefault "now plus 0 min"
   </IfModule>
3、检查是否成功 /usr/local/apache2/bin/apachectl -t
4、使用curl测试网站logo地址
curl -x127.0.0.1:80 'http://www.test.com/static/image/common/background.png' -I
返回结果如下:
HTTP/1.1 200 OK
Date: Wed, 25 May 2016 01:57:36 GMT
Server: Apache/2.2.31 (Unix) PHP/5.4.36
Last-Modified: Tue, 08 Dec 2015 02:39:16 GMT
ETag: "a6f2d-48e-52659e1375d00"
Accept-Ranges: bytes
Content-Length: 1166
Cache-Control: max-age=86400
Expires: Thu, 26 May 2016 01:57:36 GMT
Content-Type: image/png
在Cache-Control这行可知图片保存时间为86400秒即1天。

页: [1]
查看完整版本: apache配置静态缓存