Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_limit_zone_module.c @ 1012:11ffb8e4753f
stop rbtree search early if equal hash was found
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 11 Jan 2007 16:57:30 +0000 |
parents | 19118c44303f |
children | 38be15c1379a |
rev | line source |
---|---|
980 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
12 typedef struct { | |
981 | 13 u_char color; |
14 u_char len; | |
980 | 15 u_short conn; |
16 u_char data[1]; | |
17 } ngx_http_limit_zone_node_t; | |
18 | |
19 | |
20 typedef struct { | |
21 ngx_shm_zone_t *shm_zone; | |
22 ngx_rbtree_node_t *node; | |
23 } ngx_http_limit_zone_cleanup_t; | |
24 | |
25 | |
26 typedef struct { | |
987 | 27 ngx_rbtree_t *rbtree; |
28 ngx_int_t index; | |
29 ngx_str_t var; | |
30 } ngx_http_limit_zone_ctx_t; | |
31 | |
32 | |
33 typedef struct { | |
980 | 34 ngx_shm_zone_t *shm_zone; |
35 ngx_uint_t conn; | |
36 } ngx_http_limit_zone_conf_t; | |
37 | |
38 | |
39 static void ngx_http_limit_zone_cleanup(void *data); | |
40 | |
41 static void *ngx_http_limit_zone_create_conf(ngx_conf_t *cf); | |
42 static char *ngx_http_limit_zone_merge_conf(ngx_conf_t *cf, void *parent, | |
43 void *child); | |
44 static char *ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, | |
45 void *conf); | |
46 static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, | |
47 void *conf); | |
48 static ngx_int_t ngx_http_limit_zone_init(ngx_conf_t *cf); | |
49 | |
50 | |
51 static ngx_command_t ngx_http_limit_zone_commands[] = { | |
52 | |
53 { ngx_string("limit_zone"), | |
987 | 54 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3, |
980 | 55 ngx_http_limit_zone, |
56 0, | |
57 0, | |
58 NULL }, | |
59 | |
60 { ngx_string("limit_conn"), | |
987 | 61 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, |
980 | 62 ngx_http_limit_conn, |
63 NGX_HTTP_LOC_CONF_OFFSET, | |
64 0, | |
65 NULL }, | |
66 | |
67 ngx_null_command | |
68 }; | |
69 | |
70 | |
71 static ngx_http_module_t ngx_http_limit_zone_module_ctx = { | |
72 NULL, /* preconfiguration */ | |
73 ngx_http_limit_zone_init, /* postconfiguration */ | |
74 | |
75 NULL, /* create main configuration */ | |
76 NULL, /* init main configuration */ | |
77 | |
78 NULL, /* create server configuration */ | |
79 NULL, /* merge server configuration */ | |
80 | |
81 ngx_http_limit_zone_create_conf, /* create location configration */ | |
82 ngx_http_limit_zone_merge_conf /* merge location configration */ | |
83 }; | |
84 | |
85 | |
86 ngx_module_t ngx_http_limit_zone_module = { | |
87 NGX_MODULE_V1, | |
88 &ngx_http_limit_zone_module_ctx, /* module context */ | |
89 ngx_http_limit_zone_commands, /* module directives */ | |
90 NGX_HTTP_MODULE, /* module type */ | |
91 NULL, /* init master */ | |
92 NULL, /* init module */ | |
93 NULL, /* init process */ | |
94 NULL, /* init thread */ | |
95 NULL, /* exit thread */ | |
96 NULL, /* exit process */ | |
97 NULL, /* exit master */ | |
98 NGX_MODULE_V1_PADDING | |
99 }; | |
100 | |
101 | |
102 static ngx_int_t | |
103 ngx_http_limit_zone_handler(ngx_http_request_t *r) | |
104 { | |
105 size_t len, n; | |
106 uint32_t hash; | |
107 ngx_slab_pool_t *shpool; | |
108 ngx_rbtree_node_t *node, *sentinel; | |
109 ngx_pool_cleanup_t *cln; | |
110 ngx_http_variable_value_t *vv; | |
987 | 111 ngx_http_limit_zone_ctx_t *ctx; |
980 | 112 ngx_http_limit_zone_node_t *lz; |
113 ngx_http_limit_zone_conf_t *lzcf; | |
114 ngx_http_limit_zone_cleanup_t *lzcln; | |
115 | |
997
5900ec20604a
do not count connection for subrequest
Igor Sysoev <igor@sysoev.ru>
parents:
993
diff
changeset
|
116 if (r->main->limit_zone_set) { |
984
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
117 return NGX_DECLINED; |
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
118 } |
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
119 |
980 | 120 lzcf = ngx_http_get_module_loc_conf(r, ngx_http_limit_zone_module); |
121 | |
122 if (lzcf->shm_zone == NULL) { | |
123 return NGX_DECLINED; | |
124 } | |
125 | |
987 | 126 ctx = lzcf->shm_zone->data; |
127 | |
128 vv = ngx_http_get_indexed_variable(r, ctx->index); | |
980 | 129 |
130 if (vv == NULL || vv->not_found) { | |
131 return NGX_DECLINED; | |
132 } | |
133 | |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
134 len = vv->len; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
135 |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
136 if (len == 0) { |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
137 return NGX_DECLINED; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
138 } |
984
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
139 |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
140 if (len > 255) { |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
141 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
142 "the value of the \"%V\" variable " |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
143 "is more than 255 bytes: \"%V\"", |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
144 &ctx->var, vv); |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
145 return NGX_DECLINED; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
146 } |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
147 |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
148 r->main->limit_zone_set = 1; |
980 | 149 |
150 hash = ngx_crc32_short(vv->data, len); | |
151 | |
152 cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_limit_zone_cleanup_t)); | |
153 if (cln == NULL) { | |
154 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
155 } | |
156 | |
157 shpool = (ngx_slab_pool_t *) lzcf->shm_zone->shm.addr; | |
158 | |
159 ngx_shmtx_lock(&shpool->mutex); | |
160 | |
987 | 161 node = ctx->rbtree->root; |
162 sentinel = ctx->rbtree->sentinel; | |
980 | 163 |
164 while (node != sentinel) { | |
165 | |
166 if (hash < node->key) { | |
167 node = node->left; | |
168 continue; | |
169 } | |
170 | |
171 if (hash > node->key) { | |
172 node = node->right; | |
173 continue; | |
174 } | |
175 | |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
176 /* hash == node->key */ |
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
177 |
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
178 do { |
981 | 179 lz = (ngx_http_limit_zone_node_t *) &node->color; |
980 | 180 |
181 if (len == (size_t) lz->len | |
182 && ngx_strncmp(lz->data, vv->data, len) == 0) | |
183 { | |
981 | 184 if ((ngx_uint_t) lz->conn < lzcf->conn) { |
980 | 185 lz->conn++; |
186 goto done; | |
187 } | |
188 | |
189 ngx_shmtx_unlock(&shpool->mutex); | |
190 | |
191 return NGX_HTTP_SERVICE_UNAVAILABLE; | |
192 } | |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
193 |
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
194 node = node->right; |
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
195 |
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
196 } while (node != sentinel && hash == node->key); |
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
197 |
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
198 break; |
980 | 199 } |
200 | |
981 | 201 n = offsetof(ngx_rbtree_node_t, color) |
980 | 202 + offsetof(ngx_http_limit_zone_node_t, data) |
203 + len; | |
204 | |
205 node = ngx_slab_alloc_locked(shpool, n); | |
206 if (node == NULL) { | |
207 ngx_shmtx_unlock(&shpool->mutex); | |
208 return NGX_HTTP_SERVICE_UNAVAILABLE; | |
209 } | |
210 | |
981 | 211 lz = (ngx_http_limit_zone_node_t *) &node->color; |
980 | 212 |
213 node->key = hash; | |
981 | 214 lz->len = (u_char) len; |
980 | 215 lz->conn = 1; |
216 ngx_memcpy(lz->data, vv->data, len); | |
217 | |
987 | 218 ngx_rbtree_insert(ctx->rbtree, node); |
980 | 219 |
220 done: | |
221 | |
222 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
223 "limit zone: %08XD %d", node->key, lz->conn); | |
224 | |
225 ngx_shmtx_unlock(&shpool->mutex); | |
226 | |
227 cln->handler = ngx_http_limit_zone_cleanup; | |
228 lzcln = cln->data; | |
229 | |
230 lzcln->shm_zone = lzcf->shm_zone; | |
231 lzcln->node = node; | |
232 | |
233 return NGX_DECLINED; | |
234 } | |
235 | |
236 | |
237 static void | |
238 ngx_http_limit_zone_cleanup(void *data) | |
239 { | |
240 ngx_http_limit_zone_cleanup_t *lzcln = data; | |
241 | |
242 ngx_slab_pool_t *shpool; | |
243 ngx_rbtree_node_t *node; | |
987 | 244 ngx_http_limit_zone_ctx_t *ctx; |
980 | 245 ngx_http_limit_zone_node_t *lz; |
246 | |
987 | 247 ctx = lzcln->shm_zone->data; |
980 | 248 shpool = (ngx_slab_pool_t *) lzcln->shm_zone->shm.addr; |
249 node = lzcln->node; | |
981 | 250 lz = (ngx_http_limit_zone_node_t *) &node->color; |
980 | 251 |
252 ngx_shmtx_lock(&shpool->mutex); | |
253 | |
254 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0, | |
255 "limit zone cleanup: %08XD %d", node->key, lz->conn); | |
256 | |
257 lz->conn--; | |
258 | |
259 if (lz->conn == 0) { | |
987 | 260 ngx_rbtree_delete(ctx->rbtree, node); |
980 | 261 ngx_slab_free_locked(shpool, node); |
262 } | |
263 | |
264 ngx_shmtx_unlock(&shpool->mutex); | |
265 } | |
266 | |
267 | |
268 static ngx_int_t | |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
269 ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data) |
980 | 270 { |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
271 ngx_http_limit_zone_ctx_t *octx = data; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
272 |
987 | 273 ngx_slab_pool_t *shpool; |
274 ngx_rbtree_node_t *sentinel; | |
275 ngx_http_limit_zone_ctx_t *ctx; | |
980 | 276 |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
277 ctx = shm_zone->data; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
278 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
279 if (octx) { |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
280 if (ngx_strcmp(ctx->var.data, octx->var.data) != 0) { |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
281 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0, |
1001 | 282 "limit_zone \"%V\" uses the \"%V\" variable " |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
283 "while previously it used the \"%V\" variable", |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
284 &shm_zone->name, &ctx->var, &octx->var); |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
285 return NGX_ERROR; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
286 } |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
287 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
288 ctx->rbtree = octx->rbtree; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
289 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
290 return NGX_OK; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
291 } |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
292 |
980 | 293 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; |
294 | |
987 | 295 ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t)); |
296 if (ctx->rbtree == NULL) { | |
980 | 297 return NGX_ERROR; |
298 } | |
299 | |
300 sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t)); | |
301 if (sentinel == NULL) { | |
302 return NGX_ERROR; | |
303 } | |
304 | |
305 ngx_rbtree_sentinel_init(sentinel); | |
306 | |
987 | 307 ctx->rbtree->root = sentinel; |
308 ctx->rbtree->sentinel = sentinel; | |
309 ctx->rbtree->insert = ngx_rbtree_insert_value; | |
980 | 310 |
311 return NGX_OK; | |
312 } | |
313 | |
314 | |
315 static void * | |
316 ngx_http_limit_zone_create_conf(ngx_conf_t *cf) | |
317 { | |
318 ngx_http_limit_zone_conf_t *conf; | |
319 | |
320 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_zone_conf_t)); | |
321 if (conf == NULL) { | |
322 return NGX_CONF_ERROR; | |
323 } | |
324 | |
325 /* | |
326 * set by ngx_pcalloc(): | |
327 * | |
328 * conf->shm_zone = NULL; | |
329 * conf->conn = 0; | |
330 */ | |
331 | |
332 return conf; | |
333 } | |
334 | |
335 | |
336 static char * | |
337 ngx_http_limit_zone_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
338 { | |
339 ngx_http_limit_zone_conf_t *prev = parent; | |
340 ngx_http_limit_zone_conf_t *conf = child; | |
341 | |
342 if (conf->shm_zone == NULL) { | |
343 *conf = *prev; | |
344 } | |
345 | |
346 return NGX_CONF_OK; | |
347 } | |
348 | |
349 | |
350 static char * | |
351 ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
352 { | |
987 | 353 ssize_t n; |
354 ngx_str_t *value; | |
355 ngx_shm_zone_t *shm_zone; | |
356 ngx_http_limit_zone_ctx_t *ctx; | |
980 | 357 |
358 value = cf->args->elts; | |
359 | |
987 | 360 if (value[2].data[0] != '$') { |
361 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
362 "invalid variable name \"%V\"", &value[2]); | |
363 return NGX_CONF_ERROR; | |
364 } | |
365 | |
366 value[2].len--; | |
367 value[2].data++; | |
368 | |
369 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_zone_ctx_t)); | |
370 if (ctx == NULL) { | |
371 return NGX_CONF_ERROR; | |
372 } | |
373 | |
374 ctx->index = ngx_http_get_variable_index(cf, &value[2]); | |
375 if (ctx->index == NGX_ERROR) { | |
376 return NGX_CONF_ERROR; | |
377 } | |
378 | |
379 ctx->var = value[2]; | |
380 | |
381 n = ngx_parse_size(&value[3]); | |
980 | 382 |
383 if (n == NGX_ERROR) { | |
384 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
987 | 385 "invalid size of limit_zone \"%V\"", &value[3]); |
980 | 386 return NGX_CONF_ERROR; |
387 } | |
388 | |
389 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
390 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
391 "limit_zone \"%V\" is too small", &value[1]); | |
392 return NGX_CONF_ERROR; | |
393 } | |
394 | |
395 | |
396 shm_zone = ngx_shared_memory_add(cf, &value[1], n, | |
397 &ngx_http_limit_zone_module); | |
398 if (shm_zone == NULL) { | |
399 return NGX_CONF_ERROR; | |
400 } | |
401 | |
987 | 402 if (shm_zone->data) { |
403 ctx = shm_zone->data; | |
404 | |
405 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
406 "limit_zone \"%V\" is already bound to variable \"%V\"", | |
407 &value[1], &ctx->var); | |
408 return NGX_CONF_ERROR; | |
409 } | |
410 | |
980 | 411 shm_zone->init = ngx_http_limit_zone_init_zone; |
987 | 412 shm_zone->data = ctx; |
980 | 413 |
414 return NGX_CONF_OK; | |
415 } | |
416 | |
417 | |
418 static char * | |
419 ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
420 { | |
421 ngx_http_limit_zone_conf_t *lzcf = conf; | |
422 | |
423 ngx_int_t n; | |
424 ngx_str_t *value; | |
425 | |
426 value = cf->args->elts; | |
427 | |
987 | 428 lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0, |
429 &ngx_http_limit_zone_module); | |
430 if (lzcf->shm_zone == NULL) { | |
980 | 431 return NGX_CONF_ERROR; |
432 } | |
433 | |
987 | 434 n = ngx_atoi(value[2].data, value[2].len); |
435 if (n <= 0) { | |
980 | 436 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
987 | 437 "invalid number of connections \"%V\"", &value[2]); |
980 | 438 return NGX_CONF_ERROR; |
439 } | |
440 | |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
441 if (n > 65535) { |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
442 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
443 "connection limit must be less 65536"); |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
444 return NGX_CONF_ERROR; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
445 } |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
446 |
980 | 447 lzcf->conn = n; |
448 | |
449 return NGX_CONF_OK; | |
450 } | |
451 | |
452 | |
453 static ngx_int_t | |
454 ngx_http_limit_zone_init(ngx_conf_t *cf) | |
455 { | |
456 ngx_http_handler_pt *h; | |
457 ngx_http_core_main_conf_t *cmcf; | |
458 | |
459 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
460 | |
461 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers); | |
462 if (h == NULL) { | |
463 return NGX_ERROR; | |
464 } | |
465 | |
466 *h = ngx_http_limit_zone_handler; | |
467 | |
468 return NGX_OK; | |
469 } |