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

nginx配置静态缓存的过期时间

2017-01-07 14:32 337 查看
我们可以把指定文件类型日志不记录和静态缓存的过期时间结合在一起:
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx