静态元素过期时间
当用户访问网站的时候一些图片会自动缓存在电脑浏览器缓存中,当下一次访问的时候就不必要再次加载了。当超时或更新时,会重新请求加载。
[root@chy logs]# !vim
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.con(配置如下)
<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 "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>
以上为增加的内容,如下为配置的详解
<IfModule mod_expires.c>
ExpiresActive on //打开该功能的开关
ExpiresByType image/gif "access plus 1 days" (定义gif的失效时间)
ExpiresByType image/jpeg "access plus 24 hours"(定义jpeg的失效时间)
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>
测试并查看增加模块
[root@chy ~]# /usr/local/apache2.4/bin/apachectl -M |grep expire
(模块并么有打开)
[root@chy ~]# vim /usr/local/apache2.4/conf/httpd.conf
(编辑主配置文件)
#LoadModule expires_module modules/mod_expires.so
(找到expires并把它的注释去掉:LoadModule expires_module modules/mod_expires.so
)
[root@chy ~]# /usr/local/apache2.4/bin/apachectl graceful
(加载一下配置文件)
[root@chy ~]# /usr/local/apache2.4/bin/apachectl -M |grep expire
expires_module (shared)
(然后查看此模块是否存在)
测试:
[root@chy 111.com]# curl -x127.0.0.1:80 www.111.com/lf.png -I
HTTP/1.1 200 OK
Date: Thu, 03 Aug 2017 00:00:31 GMT
Server: Apache/2.4.27 (Unix) PHP/5.6.30
Last-Modified: Wed, 19 Oct 2016 08:52:35 GMT
ETag: "1bca7-53f33ee277ac0"
Accept-Ranges: bytes
Content-Length: 113831
Cache-Control: max-age=86400
Expires: Fri, 04 Aug 2017 00:00:31 GMT
Content-Type: image/png
本文转自我不是瘦子51CTO博客,原文链接:
http://blog.51cto.com/chy940405/2047933,如需转载请自行联系原作者