nginx 设置 expires and Cache-Control

源:http://nginx.org/en/docs/http/ngx_http_headers_module.html
评:
[b]add_header Cache-Control public;[/b]

Module ngx_http_headers_module

Example Configuration
Directives
add_header
expires
The ngx_http_headers_module module allows adding the “Expires” and “Cache-Control” header fields, and arbitrary fields, to a response header.

Example Configuration

expires 24h;
expires modified +24h;
expires @24h;
expires 0;
expires -1;
expires epoch;
add_header Cache-Control private;
Directives

Syntax: add_header name value [always];
Default: —
Context: http, server, location, if in location
Adds the specified field to a response header provided that the response code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307. A value can contain variables.

There could be several add_header directives. These directives are inherited from the previous level if and only if there are no add_header directives defined on the current level.

If the always parameter is specified (1.7.5), the header field will be added regardless of the response code.

[b]Syntax: expires [modified] time;
expires epoch | max | off;[/b]
Default:
expires off;
Context: http, server, location, if in location
Enables or disables adding or modifying the “Expires” and “Cache-Control” response header fields provided that the response code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307. A parameter can be a positive or negative time.

A time in the “Expires” field is computed as a sum of the current time and time specified in the directive. If the modified parameter is used (0.7.0, 0.6.32) then time is computed as a sum of the file’s modification time and time specified in the directive.

In addition, it is possible to specify a time of the day using the “@” prefix (0.7.9, 0.6.34):

expires @15h30m;
The epoch parameter corresponds to the absolute time “Thu, 01 Jan 1970 00:00:01 GMT”. The contents of the “Cache-Control” field depends on the sign of the specified time:

time is negative — “Cache-Control: no-cache”.
time is positive or zero — “Cache-Control: max-age=t”, where t is a time specified in the directive, in seconds.
[b]The max parameter sets “Expires” to the value “Thu, 31 Dec 2037 23:55:55 GMT”, and “Cache-Control” to 10 years.[/b]

The off parameter disables adding or modifying the “Expires” and “Cache-Control” response header fields.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值