模块 ngx_http_headers_module
add_trailer 过期add_header 示例 配置Directives |
这ngx_http_headers_module
模块允许添加
“Expires” 和 “Cache-Control” 标头
fields 和任意字段添加到响应标头中。
示例配置
expires 24h; expires modified +24h; expires @24h; expires 0; expires -1; expires epoch; expires $expires; add_header Cache-Control private;
Directives
语法: |
add_header
|
---|---|
默认值: | — |
上下文: |
http ,server ,location ,if in location |
将指定的字段添加到响应标头中,前提是 响应代码等于 200、201 (1.3.10)、204、206、301、302、303、304、 307 (1.1.16, 1.0.13) 或 308 (1.13.0)。 Parameter value 可以包含变量。
可能有几个add_header
Directives。
这些Directives继承自之前的配置级别
当且仅当没有add_header
Directives
在当前级别上定义。
如果always
parameter (1.7.5)、
无论响应代码如何,都会添加 Header 字段。
语法: |
add_trailer
|
---|---|
默认值: | — |
上下文: |
http ,server ,location ,if in location |
该Directives出现在版本 1.13.2 中。
将指定的字段添加到响应的末尾,前提是 响应代码等于 200、201、206、301、302、303、307 或 308。 Parameter value 可以包含变量。
可能有几个add_trailer
Directives。
这些Directives继承自之前的配置级别
当且仅当没有add_trailer
Directives
在当前级别上定义。
如果always
参数
无论响应代码如何,都将添加指定的字段。
语法: |
expires [ expires
|
---|---|
默认值: |
expires off; |
上下文: |
http ,server ,location ,if in location |
启用或禁用添加或修改 “过期” 和 “Cache-Control” 响应标头字段,前提是 响应代码等于 200、201 (1.3.10)、204、206、301、302、303、304、 307 (1.1.16, 1.0.13) 或 308 (1.13.0)。 该参数可以是正时间或负时间。
“Expires” 字段中的时间计算为
current time 和time
在Directives中指定。
如果modified
参数 (0.7.0, 0.6.32)
然后,该时间计算为文件的修改时间之和
这time
在Directives中指定。
此外,还可以使用
“” 前缀 (0.7.9, 0.6.34):@
expires @15h30m;
“Cache-Control” 字段的内容取决于 在指定时间的标志上:
- time 为负数 — “Cache-Control: no-cache”。
- 时间为正数或零 —
“缓存控制:max-age=
t
”, 哪里t
是Directives中指定的时间,以秒为单位。
这epoch
参数设置 “Expires”
设置为值 ”Thu, 01 Jan 1970 00:00:01 GMT
”,
将 “Cache-Control” 更改为 ”no-cache
”.
这max
参数设置 “Expires”
设置为值 ”Thu, 31 Dec 2037 23:55:55 GMT
”,
将“Cache-Control”降至 10 年。
这off
参数禁止添加或修改
“Expires” 和 “Cache-Control” 响应
header 字段。
最后一个参数值可以包含变量 (1.7.9):
map $sent_http_content_type $expires { default off; application/pdf 42d; ~image/ max; } expires $expires;