Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/http/ngx_http_gzip_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_gzip_module"
11
link="/en/docs/http/ngx_http_gzip_module.html"
12
lang="en"
13
rev="5">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_http_gzip_module</literal> module is a filter
19
that compresses responses using the “gzip” method.
20
This often helps to reduce the size of transmitted data by half or even more.
21
<note>
22
When using the SSL/TLS protocol, compressed responses may be subject to
23
<link url="https://en.wikipedia.org/wiki/BREACH">BREACH</link> attacks.
24
</note>
25
</para>
26
27
</section>
28
29
30
<section id="example" name="Example Configuration">
31
32
<para>
33
<example>
34
gzip on;
35
gzip_min_length 1000;
36
gzip_proxied expired no-cache no-store private auth;
37
gzip_types text/plain application/xml;
38
</example>
39
</para>
40
41
<para>
42
The <var>$gzip_ratio</var> variable can be used to log the
43
achieved compression ratio.
44
</para>
45
46
</section>
47
48
49
<section id="directives" name="Directives">
50
51
<directive name="gzip">
52
<syntax><literal>on</literal> | <literal>off</literal></syntax>
53
<default>off</default>
54
<context>http</context>
55
<context>server</context>
56
<context>location</context>
57
<context>if in location</context>
58
59
<para>
60
Enables or disables gzipping of responses.
61
</para>
62
63
</directive>
64
65
66
<directive name="gzip_buffers">
67
<syntax><value>number</value> <value>size</value></syntax>
68
<default>32 4k|16 8k</default>
69
<context>http</context>
70
<context>server</context>
71
<context>location</context>
72
73
<para>
74
Sets the <value>number</value> and <value>size</value> of buffers
75
used to compress a response.
76
By default, the buffer size is equal to one memory page.
77
This is either 4K or 8K, depending on a platform.
78
<note>
79
Until version 0.7.28, four 4K or 8K buffers were used by default.
80
</note>
81
</para>
82
83
</directive>
84
85
86
<directive name="gzip_comp_level">
87
88
<syntax><value>level</value></syntax>
89
<default>1</default>
90
<context>http</context>
91
<context>server</context>
92
<context>location</context>
93
94
<para>
95
Sets a gzip compression <value>level</value> of a response.
96
Acceptable values are in the range from 1 to 9.
97
</para>
98
99
</directive>
100
101
102
<directive name="gzip_disable">
103
<syntax><value>regex</value> ...</syntax>
104
<default/>
105
<context>http</context>
106
<context>server</context>
107
<context>location</context>
108
<appeared-in>0.6.23</appeared-in>
109
110
<para>
111
Disables gzipping of responses for requests with
112
<header>User-Agent</header> header fields matching
113
any of the specified regular expressions.
114
</para>
115
116
<para>
117
The special mask “<literal>msie6</literal>” (0.7.12) corresponds to
118
the regular expression “<literal>MSIE [4-6]\.</literal>”, but works faster.
119
Starting from version 0.8.11, “<literal>MSIE 6.0; ... SV1</literal>
120
is excluded from this mask.
121
</para>
122
123
</directive>
124
125
126
<directive name="gzip_http_version">
127
<syntax><literal>1.0</literal> | <literal>1.1</literal></syntax>
128
<default>1.1</default>
129
<context>http</context>
130
<context>server</context>
131
<context>location</context>
132
133
<para>
134
Sets the minimum HTTP version of a request required to compress a response.
135
</para>
136
137
</directive>
138
139
140
<directive name="gzip_min_length">
141
<syntax><value>length</value></syntax>
142
<default>20</default>
143
<context>http</context>
144
<context>server</context>
145
<context>location</context>
146
147
<para>
148
Sets the minimum length of a response that will be gzipped.
149
The length is determined only from the <header>Content-Length</header>
150
response header field.
151
</para>
152
153
</directive>
154
155
156
<directive name="gzip_proxied">
157
<syntax>
158
<literal>off</literal> |
159
<literal>expired</literal> |
160
<literal>no-cache</literal> |
161
<literal>no-store</literal> |
162
<literal>private</literal> |
163
<literal>no_last_modified</literal> |
164
<literal>no_etag</literal> |
165
<literal>auth</literal> |
166
<literal>any</literal>
167
...</syntax>
168
<default>off</default>
169
<context>http</context>
170
<context>server</context>
171
<context>location</context>
172
173
<para>
174
Enables or disables gzipping of responses for proxied
175
requests depending on the request and response.
176
The fact that the request is proxied is determined by
177
the presence of the <header>Via</header> request header field.
178
The directive accepts multiple parameters:
179
<list type="tag">
180
181
<tag-name><literal>off</literal></tag-name>
182
<tag-desc>
183
disables compression for all proxied requests,
184
ignoring other parameters;
185
</tag-desc>
186
187
<tag-name><literal>expired</literal></tag-name>
188
<tag-desc>
189
enables compression if a response header includes the
190
<header>Expires</header> field with a value that disables caching;
191
</tag-desc>
192
193
<tag-name><literal>no-cache</literal></tag-name>
194
<tag-desc>
195
enables compression if a response header includes the
196
<header>Cache-Control</header> field with the
197
<literal>no-cache</literal>” parameter;
198
</tag-desc>
199
200
<tag-name><literal>no-store</literal></tag-name>
201
<tag-desc>
202
enables compression if a response header includes the
203
<header>Cache-Control</header> field with the
204
<literal>no-store</literal>” parameter;
205
</tag-desc>
206
207
<tag-name><literal>private</literal></tag-name>
208
<tag-desc>
209
enables compression if a response header includes the
210
<header>Cache-Control</header> field with the
211
<literal>private</literal>” parameter;
212
</tag-desc>
213
214
<tag-name><literal>no_last_modified</literal></tag-name>
215
<tag-desc>
216
enables compression if a response header does not include the
217
<header>Last-Modified</header> field;
218
</tag-desc>
219
220
<tag-name><literal>no_etag</literal></tag-name>
221
<tag-desc>
222
enables compression if a response header does not include the
223
<header>ETag</header> field;
224
</tag-desc>
225
226
<tag-name><literal>auth</literal></tag-name>
227
<tag-desc>
228
enables compression if a request header includes the
229
<header>Authorization</header> field;
230
</tag-desc>
231
232
<tag-name><literal>any</literal></tag-name>
233
<tag-desc>
234
enables compression for all proxied requests.
235
</tag-desc>
236
237
</list>
238
</para>
239
240
</directive>
241
242
243
<directive name="gzip_types">
244
<syntax><value>mime-type</value> ...</syntax>
245
<default>text/html</default>
246
<context>http</context>
247
<context>server</context>
248
<context>location</context>
249
250
<para>
251
Enables gzipping of responses for the specified MIME types in addition
252
to “<literal>text/html</literal>”.
253
The special value “<literal>*</literal>” matches any MIME type (0.8.29).
254
Responses with the “<literal>text/html</literal>” type are always compressed.
255
</para>
256
257
</directive>
258
259
260
<directive name="gzip_vary">
261
<syntax><literal>on</literal> | <literal>off</literal></syntax>
262
<default>off</default>
263
<context>http</context>
264
<context>server</context>
265
<context>location</context>
266
267
<para>
268
Enables or disables inserting the <header>Vary: Accept-Encoding</header>
269
response header field if the directives
270
<link id="gzip"/>,
271
<link doc="ngx_http_gzip_static_module.xml" id="gzip_static"/>, or
272
<link doc="ngx_http_gunzip_module.xml" id="gunzip"/>
273
are active.
274
</para>
275
276
</directive>
277
278
</section>
279
280
281
<section id="variables" name="Embedded Variables">
282
283
<para>
284
<list type="tag">
285
286
<tag-name id="var_gzip_ratio"><var>$gzip_ratio</var></tag-name>
287
<tag-desc>achieved compression ratio, computed as the ratio between the
288
original and compressed response sizes.</tag-desc>
289
290
</list>
291
</para>
292
293
</section>
294
295
</module>
296
297