配置靜態文件在瀏覽器中緩存的時間,也叫過期時間,可以提高訪問速度。
編輯虛擬主機配置文件
[root@cp1 vhosts]# vim test.conf
修改其內容如下
無錯誤重新加載
[root@cp1 vhosts]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cp1 vhosts]# /usr/local/nginx/sbin/nginx -s reload
在瀏覽器中按F12觀察其中的max-age時間,單位是秒
也可以在curl中查看指定js的max-age
[root@cp1 vhosts]# curl -x127.0.0.1:80 'http://www.test.com/static/p_w_picpath/common/logo_88_31.gif' -I
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Thu, 23 Feb 2017 17:07:54 GMT
Content-Type: p_w_picpath/gif
Content-Length: 2528
Last-Modified: Tue, 31 May 2016 03:08:36 GMT
Connection: keep-alive
ETag: "574d0034-9e0"
Expires: Fri, 10 Mar 2017 17:07:54 GMT
Cache-Control: max-age=1296000
Accept-Ranges: bytes