我們可以把指定文件類型日誌不記錄和靜態緩存的過期時間結合在一起:
location ~ .*\.(gif|jpg|png|jpeg|bmp|swf)$ { expires 15d; #表示15天過期 # expires 24h; #表示24小時過期 access_log off; }
重新加載配置文件後,我們可以用curl來看一下配置是否正確:
[root@lnmp conf]# curl -x127.0.0.1:80 "http://www.test.com/data/attachment/forum/201701/04/142317dh9fav9kfwor3odf.jpg" -I HTTP/1.1 200 OK Server: nginx/1.4.4 Date: Wed, 04 Jan 2017 06:25:18 GMT Content-Type: image/jpeg Content-Length: 80837 Last-Modified: Wed, 04 Jan 2017 06:23:17 GMT Connection: keep-alive ETag: "586c94d5-13bc5" Expires: Thu, 19 Jan 2017 06:25:18 GMT Cache-Control: max-age=1296000 #單位爲秒,恰好爲15天 Accept-Ranges: bytes