Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/http/ngx_http_memcached_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_memcached_module"
11
link="/en/docs/http/ngx_http_memcached_module.html"
12
lang="en"
13
rev="19">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_http_memcached_module</literal> module is used to obtain
19
responses from a memcached server.
20
The key is set in the <var>$memcached_key</var> variable.
21
A response should be put in memcached in advance by means
22
external to nginx.
23
</para>
24
25
</section>
26
27
28
<section id="example" name="Example Configuration">
29
30
<para>
31
<example>
32
server {
33
location / {
34
set $memcached_key "$uri?$args";
35
memcached_pass host:11211;
36
error_page 404 502 504 = @fallback;
37
}
38
39
location @fallback {
40
proxy_pass http://backend;
41
}
42
}
43
</example>
44
</para>
45
46
</section>
47
48
49
<section id="directives" name="Directives">
50
51
<directive name="memcached_allow_upstream">
52
<syntax><value>string</value> ...</syntax>
53
<default/>
54
<context>http</context>
55
<context>server</context>
56
<context>location</context>
57
<appeared-in>1.29.3</appeared-in>
58
59
<para>
60
Defines conditions under which access to a memcached server
61
is allowed or <link id="denied">denied</link>.
62
If all string parameters are not empty
63
and not equal to “0” then the access is allowed.
64
The conditions are evaluated each time
65
before a connection to a memcached server is established.
66
Parameter values can contain variables:
67
<example>
68
geo $upstream_last_addr $allow {
69
volatile;
70
10.10.0.0/24 1;
71
}
72
73
server {
74
listen 127.0.0.1:8080;
75
76
location / {
77
memcached_pass host:11211;
78
memcached_allow_upstream $allow;
79
...
80
}
81
}
82
</example>
83
</para>
84
85
<para>
86
<note>
87
This directive is available as part of our
88
<commercial_version>commercial subscription</commercial_version>.
89
</note>
90
</para>
91
92
</directive>
93
94
95
<directive name="memcached_bind">
96
<syntax>
97
<value>address</value>
98
[<literal>transparent </literal>] |
99
<literal>off</literal></syntax>
100
<default/>
101
<context>http</context>
102
<context>server</context>
103
<context>location</context>
104
<appeared-in>0.8.22</appeared-in>
105
106
<para>
107
Makes outgoing connections to a memcached server originate
108
from the specified local IP address with an optional port (1.11.2).
109
Parameter value can contain variables (1.3.12).
110
The special value <literal>off</literal> (1.3.12) cancels the effect
111
of the <literal>memcached_bind</literal> directive
112
inherited from the previous configuration level, which allows the
113
system to auto-assign the local IP address and port.
114
</para>
115
116
<para id="memcached_bind_transparent">
117
The <literal>transparent</literal> parameter (1.11.0) allows
118
outgoing connections to a memcached server originate
119
from a non-local IP address,
120
for example, from a real IP address of a client:
121
<example>
122
memcached_bind $remote_addr transparent;
123
</example>
124
In order for this parameter to work,
125
it is usually necessary to run nginx worker processes with the
126
<link doc="../ngx_core_module.xml" id="user">superuser</link> privileges.
127
On Linux it is not required (1.13.8) as if
128
the <literal>transparent</literal> parameter is specified, worker processes
129
inherit the <literal>CAP_NET_RAW</literal> capability from the master process.
130
It is also necessary to configure kernel routing table
131
to intercept network traffic from the memcached server.
132
</para>
133
134
</directive>
135
136
137
<directive name="memcached_bind_dynamic">
138
<syntax><literal>on</literal> | <literal>off</literal></syntax>
139
<default>off</default>
140
<context>http</context>
141
<context>server</context>
142
<context>location</context>
143
<appeared-in>1.29.3</appeared-in>
144
145
<para>
146
When enabled, makes the <link id="memcached_bind">bind</link> operation
147
at each connection attempt.
148
</para>
149
150
<para>
151
<note>
152
This directive is available as part of our
153
<commercial_version>commercial subscription</commercial_version>.
154
</note>
155
</para>
156
157
</directive>
158
159
160
<directive name="memcached_buffer_size">
161
<syntax><value>size</value></syntax>
162
<default>4k|8k</default>
163
<context>http</context>
164
<context>server</context>
165
<context>location</context>
166
167
<para>
168
Sets the <value>size</value> of the buffer used for reading the response
169
received from the memcached server.
170
The response is passed to the client synchronously, as soon as it is received.
171
</para>
172
173
</directive>
174
175
176
<directive name="memcached_connect_timeout">
177
<syntax><value>time</value></syntax>
178
<default>60s</default>
179
<context>http</context>
180
<context>server</context>
181
<context>location</context>
182
183
<para>
184
Defines a timeout for establishing a connection with a memcached server.
185
It should be noted that this timeout cannot usually exceed 75 seconds.
186
</para>
187
188
</directive>
189
190
191
<directive name="memcached_gzip_flag">
192
<syntax><value>flag</value></syntax>
193
<default></default>
194
<context>http</context>
195
<context>server</context>
196
<context>location</context>
197
<appeared-in>1.3.6</appeared-in>
198
199
<para>
200
Enables the test for the <value>flag</value> presence in the memcached
201
server response and sets the “<literal>Content-Encoding</literal>
202
response header field to “<literal>gzip</literal>
203
if the flag is set.
204
</para>
205
206
</directive>
207
208
209
<directive name="memcached_next_upstream">
210
<syntax>
211
<literal>error</literal> |
212
<literal>timeout</literal> |
213
<literal>denied</literal> |
214
<literal>invalid_response</literal> |
215
<literal>not_found</literal> |
216
<literal>off</literal>
217
...</syntax>
218
<default>error timeout</default>
219
<context>http</context>
220
<context>server</context>
221
<context>location</context>
222
223
<para>
224
Specifies in which cases a request should be passed to the next server:
225
<list type="tag">
226
227
<tag-name><literal>error</literal></tag-name>
228
<tag-desc>an error occurred while establishing a connection with the
229
server, passing a request to it, or reading the response header;</tag-desc>
230
231
<tag-name><literal>timeout</literal></tag-name>
232
<tag-desc>a timeout has occurred while establishing a connection with the
233
server, passing a request to it, or reading the response header;</tag-desc>
234
235
<tag-name id="denied"><literal>denied</literal></tag-name>
236
<tag-desc>the server <link id="memcached_allow_upstream">denied</link>
237
the connection (1.29.3);
238
<para>
239
<note>
240
This parameter is available as part of our
241
<commercial_version>commercial subscription</commercial_version>.
242
</note>
243
</para>
244
</tag-desc>
245
246
<tag-name><literal>invalid_response</literal></tag-name>
247
<tag-desc>a server returned an empty or invalid response;</tag-desc>
248
249
<tag-name><literal>not_found</literal></tag-name>
250
<tag-desc>a response was not found on the server;</tag-desc>
251
252
<tag-name><literal>off</literal></tag-name>
253
<tag-desc>disables passing a request to the next server.</tag-desc>
254
255
</list>
256
</para>
257
258
<para>
259
One should bear in mind that passing a request to the next server is
260
only possible if nothing has been sent to a client yet.
261
That is, if an error or timeout occurs in the middle of the
262
transferring of a response, fixing this is impossible.
263
</para>
264
265
<para>
266
The directive also defines what is considered an
267
<link doc="ngx_http_upstream_module.xml" id="max_fails">unsuccessful
268
attempt</link> of communication with a server.
269
The cases of <literal>error</literal>, <literal>timeout</literal>,
270
<literal>denied</literal> and
271
<literal>invalid_response</literal> are always considered unsuccessful attempts,
272
even if they are not specified in the directive.
273
The case of <literal>not_found</literal>
274
is never considered an unsuccessful attempt.
275
</para>
276
277
<para>
278
Passing a request to the next server can be limited by
279
<link id="memcached_next_upstream_tries">the number of tries</link>
280
and by <link id="memcached_next_upstream_timeout">time</link>.
281
</para>
282
283
</directive>
284
285
286
<directive name="memcached_next_upstream_timeout">
287
<syntax><value>time</value></syntax>
288
<default>0</default>
289
<context>http</context>
290
<context>server</context>
291
<context>location</context>
292
<appeared-in>1.7.5</appeared-in>
293
294
<para>
295
Limits the time during which a request can be passed to the
296
<link id="memcached_next_upstream">next server</link>.
297
The <literal>0</literal> value turns off this limitation.
298
</para>
299
300
</directive>
301
302
303
<directive name="memcached_next_upstream_tries">
304
<syntax><value>number</value></syntax>
305
<default>0</default>
306
<context>http</context>
307
<context>server</context>
308
<context>location</context>
309
<appeared-in>1.7.5</appeared-in>
310
311
<para>
312
Limits the number of possible tries for passing a request to the
313
<link id="memcached_next_upstream">next server</link>.
314
The <literal>0</literal> value turns off this limitation.
315
</para>
316
317
</directive>
318
319
320
<directive name="memcached_pass">
321
<syntax><value>address</value></syntax>
322
<default/>
323
<context>location</context>
324
<context>if in location</context>
325
326
<para>
327
Sets the memcached server address.
328
The address can be specified as a domain name or IP address,
329
and a port:
330
<example>
331
memcached_pass localhost:11211;
332
</example>
333
or as a UNIX-domain socket path:
334
<example>
335
memcached_pass unix:/tmp/memcached.socket;
336
</example>
337
</para>
338
339
<para>
340
If a domain name resolves to several addresses, all of them will be
341
used in a round-robin fashion.
342
In addition, an address can be specified as a
343
<link doc="ngx_http_upstream_module.xml">server group</link>.
344
</para>
345
346
</directive>
347
348
349
<directive name="memcached_read_timeout">
350
<syntax><value>time</value></syntax>
351
<default>60s</default>
352
<context>http</context>
353
<context>server</context>
354
<context>location</context>
355
356
<para>
357
Defines a timeout for reading a response from the memcached server.
358
The timeout is set only between two successive read operations,
359
not for the transmission of the whole response.
360
If the memcached server does not transmit anything within this time,
361
the connection is closed.
362
</para>
363
364
</directive>
365
366
367
<directive name="memcached_send_timeout">
368
<syntax><value>time</value></syntax>
369
<default>60s</default>
370
<context>http</context>
371
<context>server</context>
372
<context>location</context>
373
374
<para>
375
Sets a timeout for transmitting a request to the memcached server.
376
The timeout is set only between two successive write operations,
377
not for the transmission of the whole request.
378
If the memcached server does not receive anything within this time,
379
the connection is closed.
380
</para>
381
382
</directive>
383
384
385
<directive name="memcached_socket_keepalive">
386
<syntax><literal>on</literal> | <literal>off</literal></syntax>
387
<default>off</default>
388
<context>http</context>
389
<context>server</context>
390
<context>location</context>
391
<appeared-in>1.15.6</appeared-in>
392
393
<para>
394
Configures the “TCP keepalive” behavior
395
for outgoing connections to a memcached server.
396
By default, the operating system’s settings are in effect for the socket.
397
If the directive is set to the value “<literal>on</literal>”, the
398
<c-def>SO_KEEPALIVE</c-def> socket option is turned on for the socket.
399
</para>
400
401
</directive>
402
403
</section>
404
405
406
<section id="variables" name="Embedded Variables">
407
408
<para>
409
<list type="tag">
410
411
<tag-name id="var_memcached_key"><var>$memcached_key</var></tag-name>
412
<tag-desc>
413
Defines a key for obtaining response from a memcached server.
414
</tag-desc>
415
416
</list>
417
</para>
418
419
</section>
420
421
</module>
422
423