您的位置:首页 > 运维架构 > Apache

Apache静态缓存配置

2016-01-07 13:44 726 查看
Apache配置静态缓存
[root@Linux9 logs]# apachectl -M #查看expires_modul模块加载
expires_module (shared)

[root@Linux9 logs]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
以下为静态缓存配置:

45 <IfModule mod_expires.c>
46 ExpiresActive on
47 ExpiresByType image/gif "access plus 1 days"
48 ExpiresByType image/jpeg "access plus 24 hours"
49 ExpiresByType image/png "access plus 24 hours"
50 ExpiresByType test/css "now plus 2 hours"
51 ExpiresByType application/x-javascripts "now plus 2 hours"
52 ExpiresByType application/x-shockwave-flash "now plus 2 hours"
53 ExpiresDefault "now plus 0 min"
54 </IfModule>

[root@linux9 logs]# apachectl -t
Syntax OK

[root@linux9 logs]# apachectl graceful

注:ExpiresActive on #缓存开关 启用或禁产生"Expires:"和"Cache-Control:"头的功能
ExpiresDefault "now plus 0 min" #默认不缓存 设置了其作用范围内的所有文档的默认有效期的计算方法
修改ExpiresByType image/png "access plus 12 hours"
[root@Linux9 apache2]# vim conf/extra/httpd-vhosts.conf
[root@Linux9 apache2]# apachectl graceful
[root@Linux9 apache2]# curl -x192.168.25.57:80 'http://www.yh.com/static/image/common/logo.png' -I
HTTP/1.1 200 OK
Date: Thu, 07 Jan 2016 03:53:06 GMT
Server: Apache/2.4.17 (Unix) PHP/5.5.9
Last-Modified: Tue, 08 Dec 2015 02:39:16 GMT
ETag: "1149-52659e1375d00"
Accept-Ranges: bytes
Content-Length: 4425
Cache-Control: max-age=43200
Expires: Thu, 07 Jan 2016 15:53:06 GMT
Content-Type: image/png
如果修改:ExpiresByType image/gif "access plus 2 days"
Cache-Control: max-age=172800 两天时间
注:now和access,hour和hours都一样用!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  配置 Apache 静态缓存