瀏覽器訪問網站的圖片時會把靜態的文件緩存在本地電腦裏,這樣下次再訪問時就不用去遠程下載了
增加配置
<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