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
编辑虚拟主机配置文件
[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
相关文章推荐
- LNMP - nginx配置静态文件过期时间
- nginx配置静态文件过期时间
- LNMP架构 (3) 之 Nginx访问日志、日志切割、静态文件不记录日志和过期时间
- nginx配置静态文件过期时间
- 2.1-nginx配置静态文件过期时间
- Nginx 配置静态文件过期时间&防盗链
- Nginx配置——配置静态文件过期时间
- CentOS7 Nginx配置--静态文件过期时间、防盗链、访问控制
- nginx配置静态文件过期时间
- nginx配置静态文件过期时间
- LNMP - Nginx配置静态文件缓存时间
- Nginx如何配置静态文件过期时间
- 【LNMP】Nginx访问日志、Nginx日志切割、静态文件不记录日志和过期时间
- nginx配置静态文件过期时间
- Nginx访问日志、Nginx日志切割 、静态文件不记录日志和过期时间
- linux的访问日志不记录静态文件、切割、静态元素过期时间配置
- Nginx访问日志,Nginx日志切割,静态文件不记录日志和过期时间
- nginx配置1:借助Nginx搭建反向代理服务器与缓存静态文件
- nginx配置1:借助Nginx搭建反向代理服务器与缓存静态文件
- nginx配置静态文件expires时间 cache-control