Nginx参考手册
ngx_http_headers_module
ngx_http_headers_module
- 示例配置
- 指令
- add_header
- add_trailer
- 到期
该ngx_http_headers_module模块允许将“Expires”和“Cache-Control”头字段以及任意字段添加到响应头。
示例配置
expires 24h;
expires modified +24h;
expires @24h;
expires 0;
expires -1;
expires epoch;
expires $expires;
add_header Cache-Control private;
指令
句法: |
始终为add_header名称值; |
|---|---|
默认: |
— |
语境: |
http,服务器,位置,如果在指定位置 |
如果响应代码等于200,201(1.3.10),204,206,301,302,303,304,307(1.1.16,1.0.13)或308(1.13),则将指定的字段添加到响应头中。 .0)。该值可以包含变量。
可能有几个add_header指令。当且仅当没有add_header在当前级别上定义的指令时,这些指令才从前一级继承。
如果指定了always参数(1.7.5),则无论响应代码如何,标题字段都将被添加。
句法: |
始终为add_trailer名称值始终; |
|---|---|
默认: |
— |
语境: |
http,服务器,位置,如果在指定位置 |
如果响应代码等于200,201,206,301,302,303,307或308,则将指定的字段添加到响应的末尾。该值可以包含变量。
可能有几个add_trailer指令。当且仅当没有add_trailer在当前级别上定义的指令时,这些指令才从前一级继承。
如果指定了always参数,则无论响应代码如何,都会添加指定的字段。
句法: |
expires modified time;expires epoch | max | off; |
|---|---|
默认: |
expires off 关闭; |
语境: |
http,服务器,位置,如果在位置 |
如果响应代码等于200,201(1.3.10),204,206,301,302,303,304,307(1.1。),则启用或禁用添加或修改“Expires”和“Cache-Control”响应头字段。 16,1.0.13)或308(1.13.0)。参数可以是正值或负值。
“过期”字段中的时间计算为当前时间和time指令中指定的总和。如果使用modified参数(0.7.0,0.6.32),则时间计算为文件修改时间与time指令中指定的时间之和。
另外,可以使用“ @”前缀(0.7.9,0.6.34)指定一天的时间:
expires @15h30m;
该epoch参数对应于绝对时间“ Thu, 01 Jan 1970 00:00:01 GMT”。“缓存控制”字段的内容取决于指定时间的符号:
- 时间是负的 - “Cache-Control:no-cache”。
- 时间为正或零 - “Cache-Control:max-age =
t”,其中t是指令中指定的时间,以秒为单位。
该max参数将“Expires”设置为值“ Thu, 31 Dec 2037 23:55:55 GMT”,并将“Cache-Control”设置为10年。
该off参数禁止添加或修改“Expires”和“Cache-Control”响应头字段。
最后一个参数值可以包含变量(1.7.9):
map $sent_http_content_type $expires {
default off;
application/pdf 42d;
~image/ max;
}
expires $expires;
| ngx_http_headers_module |
|---|
Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器,可在 BSD-like 协议下发行。其特点是占有内存少,并发能力强。
| 主页 | https://nginx.org/ |
| 源码 | http://hg.nginx.org/nginx |
| 发布版本 | 1.13.6 |
加载中,请稍侯......