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