浏览器访问网站的图片时会把静态的文件缓存在本地电脑里,这样下次再访问时就不用去远程下载了
增加配置
<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>
查看是否有这个模块:/usr/local/apache2.4/bin/apachectl -M | grep expire
若没有需要编辑主配置文件:vim /usr/local/apache2.4/conf/httpd.conf
把expires_module这行的注释去掉
重新加载
在浏览器打开网页,F12打开代码模式,CTRL+F5清除缓存,看cache-control: max-age
也可以在服务器中使用curl命令查看:curl -x127.0.0.1:80 111.com/qq.png -I