Apache静态缓存配置

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,配置,静态缓存)