Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/http/ngx_http_headers_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) Igor Sysoev
5
Copyright (C) Nginx, Inc.
6
-->
7
8
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
9
10
<module name="Module ngx_http_headers_module"
11
link="/en/docs/http/ngx_http_headers_module.html"
12
lang="en"
13
rev="14">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_http_headers_module</literal> module allows adding
19
the <header>Expires</header> and <header>Cache-Control</header> header
20
fields, and arbitrary fields, to a response header.
21
</para>
22
23
</section>
24
25
26
<section id="example" name="Example Configuration">
27
28
<para>
29
<example>
30
expires 24h;
31
expires modified +24h;
32
expires @24h;
33
expires 0;
34
expires -1;
35
expires epoch;
36
expires $expires;
37
add_header Cache-Control private;
38
</example>
39
</para>
40
41
</section>
42
43
44
<section id="directives" name="Directives">
45
46
<directive name="add_header">
47
<syntax>
48
<value>name</value> <value>value</value>
49
[<literal>always</literal>]</syntax>
50
<default/>
51
<context>http</context>
52
<context>server</context>
53
<context>location</context>
54
<context>if in location</context>
55
56
<para>
57
Adds the specified field to a response header provided that
58
the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304,
59
307 (1.1.16, 1.0.13), or 308 (1.13.0).
60
Parameter value can contain variables.
61
</para>
62
63
<para id="add_header_default_inherit">
64
There could be several <literal>add_header</literal> directives.
65
These directives are inherited from the previous configuration level
66
if and only if there are no <literal>add_header</literal> directives
67
defined on the current level.
68
Inheritance rules can be redefined with the
69
<link id="add_header_inherit"/> directive (1.29.3).
70
</para>
71
72
<para>
73
If the <literal>always</literal> parameter is specified (1.7.5),
74
the header field will be added regardless of the response code.
75
</para>
76
77
</directive>
78
79
80
<directive name="add_header_inherit">
81
<syntax>
82
<literal>on</literal> |
83
<literal>off</literal> |
84
<literal>merge</literal></syntax>
85
<default>on</default>
86
<context>http</context>
87
<context>server</context>
88
<context>location</context>
89
<context>if in location</context>
90
<appeared-in>1.29.3</appeared-in>
91
92
<para>
93
Allows altering inheritance rules for the values specified in the
94
<link id="add_header"/> directives.
95
By default, the
96
<link id="add_header_default_inherit">standard</link> inheritance model is used.
97
</para>
98
99
<para>
100
The <literal>merge</literal> parameter enables appending values
101
from the previous level to the values defined at the current level.
102
</para>
103
104
<para>
105
The <literal>off</literal> parameter cancels inheritance of the values
106
from the previous configuration level.
107
</para>
108
109
<para>
110
The inheritance rules themselves are inherited in a standard way.
111
For example, <literal>add_header_inherit merge;</literal>
112
specified at the top level will
113
be inherited in all nested levels recursively unless redefined later.
114
</para>
115
116
</directive>
117
118
119
<directive name="add_trailer">
120
<syntax>
121
<value>name</value> <value>value</value>
122
[<literal>always</literal>]</syntax>
123
<default/>
124
<context>http</context>
125
<context>server</context>
126
<context>location</context>
127
<context>if in location</context>
128
<appeared-in>1.13.2</appeared-in>
129
130
<para>
131
Adds the specified field to the end of a response provided that
132
the response code equals 200, 201, 206, 301, 302, 303, 307, or 308.
133
Parameter value can contain variables.
134
</para>
135
136
<para id="add_trailer_default_inherit">
137
There could be several <literal>add_trailer</literal> directives.
138
These directives are inherited from the previous configuration level
139
if and only if there are no <literal>add_trailer</literal> directives
140
defined on the current level.
141
Inheritance rules can be redefined with the
142
<link id="add_trailer_inherit"/> directive (1.29.3).
143
</para>
144
145
<para>
146
If the <literal>always</literal> parameter is specified
147
the specified field will be added regardless of the response code.
148
</para>
149
150
</directive>
151
152
153
<directive name="add_trailer_inherit">
154
<syntax>
155
<literal>on</literal> |
156
<literal>off</literal> |
157
<literal>merge</literal></syntax>
158
<default>on</default>
159
<context>http</context>
160
<context>server</context>
161
<context>location</context>
162
<context>if in location</context>
163
<appeared-in>1.29.3</appeared-in>
164
165
<para>
166
Allows altering inheritance rules for the values specified in the
167
<link id="add_trailer"/> directives.
168
By default, the
169
<link id="add_trailer_default_inherit">standard</link> inheritance model is used.
170
</para>
171
172
<para>
173
The <literal>merge</literal> parameter enables appending values
174
from the previous level to the values defined at the current level.
175
</para>
176
177
<para>
178
The <literal>off</literal> parameter cancels inheritance of the values
179
from the previous configuration level.
180
</para>
181
182
<para>
183
The inheritance rules themselves are inherited in a standard way.
184
For example, <literal>add_trailer_inherit merge;</literal>
185
specified at the top level will
186
be inherited in all nested levels recursively unless redefined later.
187
</para>
188
189
</directive>
190
191
192
<directive name="expires">
193
<syntax>[<literal>modified</literal>] <value>time</value></syntax>
194
<syntax>
195
<literal>epoch</literal> |
196
<literal>max</literal> |
197
<literal>off</literal></syntax>
198
<default>off</default>
199
<context>http</context>
200
<context>server</context>
201
<context>location</context>
202
<context>if in location</context>
203
204
<para>
205
Enables or disables adding or modifying the <header>Expires</header>
206
and <header>Cache-Control</header> response header fields provided that
207
the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304,
208
307 (1.1.16, 1.0.13), or 308 (1.13.0).
209
The parameter can be a positive or negative
210
<link doc="../syntax.xml">time</link>.
211
</para>
212
213
<para>
214
The time in the <header>Expires</header> field is computed as a sum of the
215
current time and <value>time</value> specified in the directive.
216
If the <literal>modified</literal> parameter is used (0.7.0, 0.6.32)
217
then the time is computed as a sum of the file’s modification time and
218
the <value>time</value> specified in the directive.
219
</para>
220
221
<para>
222
In addition, it is possible to specify a time of day using
223
the “<literal>@</literal>” prefix (0.7.9, 0.6.34):
224
<example>
225
expires @15h30m;
226
</example>
227
</para>
228
229
<para>
230
The contents of the <header>Cache-Control</header> field depends
231
on the sign of the specified time:
232
<list type="bullet">
233
234
<listitem>
235
time is negative — <header>Cache-Control: no-cache</header>.
236
</listitem>
237
238
<listitem>
239
time is positive or zero —
240
<header>Cache-Control: max-age=<value>t</value></header>,
241
where <value>t</value> is a time specified in the directive, in seconds.
242
</listitem>
243
244
</list>
245
</para>
246
247
<para>
248
The <literal>epoch</literal> parameter sets <header>Expires</header>
249
to the value “<literal>Thu, 01 Jan 1970 00:00:01 GMT</literal>”,
250
and <header>Cache-Control</header> to “<literal>no-cache</literal>”.
251
</para>
252
253
<para>
254
The <literal>max</literal> parameter sets <header>Expires</header>
255
to the value “<literal>Thu, 31 Dec 2037 23:55:55 GMT</literal>”,
256
and <header>Cache-Control</header> to 10 years.
257
</para>
258
259
<para>
260
The <literal>off</literal> parameter disables adding or modifying the
261
<header>Expires</header> and <header>Cache-Control</header> response
262
header fields.
263
</para>
264
265
<para>
266
The last parameter value can contain variables (1.7.9):
267
<example>
268
map $sent_http_content_type $expires {
269
default off;
270
application/pdf 42d;
271
~image/ max;
272
}
273
274
expires $expires;
275
</example>
276
</para>
277
278
</directive>
279
280
</section>
281
282
</module>
283
284