本文共 1970 字,大约阅读时间需要 6 分钟。
当用户访问网站的时候一些图片会自动缓存在电脑浏览器缓存中,当下一次访问的时候就不必要再次加载了。当超时或更新时,会重新请求加载。
[root@chy logs]# !vimvim /usr/local/apache2.4/conf/extra/httpd-vhosts.con(配置如下)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" 以上为增加的内容,如下为配置的详解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"
测试并查看增加模块
[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 -IHTTP/1.1 200 OKDate: Thu, 03 Aug 2017 00:00:31 GMTServer: Apache/2.4.27 (Unix) PHP/5.6.30Last-Modified: Wed, 19 Oct 2016 08:52:35 GMTETag: "1bca7-53f33ee277ac0"Accept-Ranges: bytesContent-Length: 113831Cache-Control: max-age=86400Expires: Fri, 04 Aug 2017 00:00:31 GMT
Content-Type: image/png
本文转自我不是瘦子51CTO博客,原文链接:
http://blog.51cto.com/chy940405/2047933,如需转载请自行联系原作者