使用 expires
参数。
不缓存
输出 Response Headers:
当文件没有变更时会返回 304 ,有变更时会是 200 ,如果强制命中 200 可以再添加: if_modified_since off;
忽略 Request Headers 里的 If-Modified-Since
字段。
缓存
1d 为 1 天,单位如下:
1 2 3 4 5 6 7 8
| ms milliseconds s seconds m minutes h hours d days w weeks M months,30 days y years,365 days
|
如果希望最大缓存可以:
1 2 3
| server { expires max; }
|
输出 Response Headers:
1
| Cache-Control:max-age=315360000
|
根据链接设置缓存时间
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| server { set $expires_time 1M; if ($request_uri ~* ^/admin(\/.*)?$) { set $expires_time -1; } if ($request_uri ~* ^/static(\/.*)?$) { set $expires_time max; } expires $expires_time; }
|