配置静态文件在浏览器中缓存的时间,也叫过期时间,可以提高访问速度。
编辑虚拟主机配置文件
[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
转载于:https://blog.51cto.com/rachy/1901168