您的位置:首页 > 运维架构 > Nginx

LNMP搭建10:Nginx配置静态文件过期时间

2017-02-25 12:57 399 查看
配置静态文件在浏览器中缓存的时间,也叫过期时间,可以提高访问速度。
编辑虚拟主机配置文件
[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/image/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: image/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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  搭建 Nginx LNMP