3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
8 #include <ngx_config.h>
13 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
14 static ngx_int_t ngx_http_init_phases(ngx_conf_t *cf,
15 ngx_http_core_main_conf_t *cmcf);
16 static ngx_int_t ngx_http_init_headers_in_hash(ngx_conf_t *cf,
17 ngx_http_core_main_conf_t *cmcf);
18 static ngx_int_t ngx_http_init_phase_handlers(ngx_conf_t *cf,
19 ngx_http_core_main_conf_t *cmcf);
21 static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf,
22 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
23 ngx_http_listen_opt_t *lsopt);
24 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
25 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
26 ngx_http_listen_opt_t *lsopt);
27 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf,
28 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr);
30 static char *ngx_http_merge_servers(ngx_conf_t *cf,
31 ngx_http_core_main_conf_t *cmcf, ngx_http_module_t *module,
32 ngx_uint_t ctx_index);
33 static char *ngx_http_merge_locations(ngx_conf_t *cf,
34 ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module,
35 ngx_uint_t ctx_index);
36 static ngx_int_t ngx_http_init_locations(ngx_conf_t *cf,
37 ngx_http_core_srv_conf_t *cscf, ngx_http_core_loc_conf_t *pclcf);
38 static ngx_int_t ngx_http_init_static_location_trees(ngx_conf_t *cf,
39 ngx_http_core_loc_conf_t *pclcf);
40 static ngx_int_t ngx_http_cmp_locations(const ngx_queue_t *one,
41 const ngx_queue_t *two);
42 static ngx_int_t ngx_http_join_exact_locations(ngx_conf_t *cf,
43 ngx_queue_t *locations);
44 static void ngx_http_create_locations_list(ngx_queue_t *locations,
46 static ngx_http_location_tree_node_t *
47 ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations,
50 static ngx_int_t ngx_http_optimize_servers(ngx_conf_t *cf,
51 ngx_http_core_main_conf_t *cmcf, ngx_array_t *ports);
52 static ngx_int_t ngx_http_server_names(ngx_conf_t *cf,
53 ngx_http_core_main_conf_t *cmcf, ngx_http_conf_addr_t *addr);
54 static ngx_int_t ngx_http_cmp_conf_addrs(const void *one, const void *two);
55 static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(const void *one,
58 static ngx_int_t ngx_http_init_listening(ngx_conf_t *cf,
59 ngx_http_conf_port_t *port);
60 static ngx_listening_t *ngx_http_add_listening(ngx_conf_t *cf,
61 ngx_http_conf_addr_t *addr);
62 static ngx_int_t ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport,
63 ngx_http_conf_addr_t *addr);
65 static ngx_int_t ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport,
66 ngx_http_conf_addr_t *addr);
69 ngx_uint_t ngx_http_max_module;
72 ngx_http_output_header_filter_pt ngx_http_top_header_filter;
73 ngx_http_output_body_filter_pt ngx_http_top_body_filter;
74 ngx_http_request_body_filter_pt ngx_http_top_request_body_filter;
77 ngx_str_t ngx_http_html_default_types[] = {
78 ngx_string("text/html"),
83 static ngx_command_t ngx_http_commands[] = {
86 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
96 static ngx_core_module_t ngx_http_module_ctx = {
103 ngx_module_t ngx_http_module = {
105 &ngx_http_module_ctx, /* module context */
106 ngx_http_commands, /* module directives */
107 NGX_CORE_MODULE, /* module type */
108 NULL, /* init master */
109 NULL, /* init module */
110 NULL, /* init process */
111 NULL, /* init thread */
112 NULL, /* exit thread */
113 NULL, /* exit process */
114 NULL, /* exit master */
115 NGX_MODULE_V1_PADDING
120 ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
125 ngx_http_module_t *module;
126 ngx_http_conf_ctx_t *ctx;
127 ngx_http_core_loc_conf_t *clcf;
128 ngx_http_core_srv_conf_t **cscfp;
129 ngx_http_core_main_conf_t *cmcf;
131 if (*(ngx_http_conf_ctx_t **) conf) {
132 return "is duplicate";
135 /* the main http context */
137 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
139 return NGX_CONF_ERROR;
142 *(ngx_http_conf_ctx_t **) conf = ctx;
145 /* count the number of the http modules and set up their indices */
147 ngx_http_max_module = ngx_count_modules(cf->cycle, NGX_HTTP_MODULE);
150 /* the http main_conf context, it is the same in the all http contexts */
152 ctx->main_conf = ngx_pcalloc(cf->pool,
153 sizeof(void *) * ngx_http_max_module);
154 if (ctx->main_conf == NULL) {
155 return NGX_CONF_ERROR;
160 * the http null srv_conf context, it is used to merge
161 * the server{}s' srv_conf's
164 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
165 if (ctx->srv_conf == NULL) {
166 return NGX_CONF_ERROR;
171 * the http null loc_conf context, it is used to merge
172 * the server{}s' loc_conf's
175 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
176 if (ctx->loc_conf == NULL) {
177 return NGX_CONF_ERROR;
182 * create the main_conf's, the null srv_conf's, and the null loc_conf's
183 * of the all http modules
186 for (m = 0; cf->cycle->modules[m]; m++) {
187 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {
191 module = cf->cycle->modules[m]->ctx;
192 mi = cf->cycle->modules[m]->ctx_index;
194 if (module->create_main_conf) {
195 ctx->main_conf[mi] = module->create_main_conf(cf);
196 if (ctx->main_conf[mi] == NULL) {
197 return NGX_CONF_ERROR;
201 if (module->create_srv_conf) {
202 ctx->srv_conf[mi] = module->create_srv_conf(cf);
203 if (ctx->srv_conf[mi] == NULL) {
204 return NGX_CONF_ERROR;
208 if (module->create_loc_conf) {
209 ctx->loc_conf[mi] = module->create_loc_conf(cf);
210 if (ctx->loc_conf[mi] == NULL) {
211 return NGX_CONF_ERROR;
219 for (m = 0; cf->cycle->modules[m]; m++) {
220 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {
224 module = cf->cycle->modules[m]->ctx;
226 if (module->preconfiguration) {
227 if (module->preconfiguration(cf) != NGX_OK) {
228 return NGX_CONF_ERROR;
233 /* parse inside the http{} block */
235 cf->module_type = NGX_HTTP_MODULE;
236 cf->cmd_type = NGX_HTTP_MAIN_CONF;
237 rv = ngx_conf_parse(cf, NULL);
239 if (rv != NGX_CONF_OK) {
244 * init http{} main_conf's, merge the server{}s' srv_conf's
245 * and its location{}s' loc_conf's
248 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
249 cscfp = cmcf->servers.elts;
251 for (m = 0; cf->cycle->modules[m]; m++) {
252 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {
256 module = cf->cycle->modules[m]->ctx;
257 mi = cf->cycle->modules[m]->ctx_index;
259 /* init http{} main_conf's */
261 if (module->init_main_conf) {
262 rv = module->init_main_conf(cf, ctx->main_conf[mi]);
263 if (rv != NGX_CONF_OK) {
268 rv = ngx_http_merge_servers(cf, cmcf, module, mi);
269 if (rv != NGX_CONF_OK) {
275 /* create location trees */
277 for (s = 0; s < cmcf->servers.nelts; s++) {
279 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index];
281 if (ngx_http_init_locations(cf, cscfp[s], clcf) != NGX_OK) {
282 return NGX_CONF_ERROR;
285 if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) {
286 return NGX_CONF_ERROR;
291 if (ngx_http_init_phases(cf, cmcf) != NGX_OK) {
292 return NGX_CONF_ERROR;
295 if (ngx_http_init_headers_in_hash(cf, cmcf) != NGX_OK) {
296 return NGX_CONF_ERROR;
300 for (m = 0; cf->cycle->modules[m]; m++) {
301 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {
305 module = cf->cycle->modules[m]->ctx;
307 if (module->postconfiguration) {
308 if (module->postconfiguration(cf) != NGX_OK) {
309 return NGX_CONF_ERROR;
314 if (ngx_http_variables_init_vars(cf) != NGX_OK) {
315 return NGX_CONF_ERROR;
319 * http{}'s cf->ctx was needed while the configuration merging
320 * and in postconfiguration process
326 if (ngx_http_init_phase_handlers(cf, cmcf) != NGX_OK) {
327 return NGX_CONF_ERROR;
331 /* optimize the lists of ports, addresses and server names */
333 if (ngx_http_optimize_servers(cf, cmcf, cmcf->ports) != NGX_OK) {
334 return NGX_CONF_ERROR;
348 ngx_http_init_phases(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
350 if (ngx_array_init(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers,
351 cf->pool, 1, sizeof(ngx_http_handler_pt))
357 if (ngx_array_init(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers,
358 cf->pool, 1, sizeof(ngx_http_handler_pt))
364 if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers,
365 cf->pool, 1, sizeof(ngx_http_handler_pt))
371 if (ngx_array_init(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers,
372 cf->pool, 1, sizeof(ngx_http_handler_pt))
378 if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers,
379 cf->pool, 2, sizeof(ngx_http_handler_pt))
385 if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,
386 cf->pool, 4, sizeof(ngx_http_handler_pt))
392 if (ngx_array_init(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers,
393 cf->pool, 1, sizeof(ngx_http_handler_pt))
404 ngx_http_init_headers_in_hash(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
406 ngx_array_t headers_in;
408 ngx_hash_init_t hash;
409 ngx_http_header_t *header;
411 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t))
417 for (header = ngx_http_headers_in; header->name.len; header++) {
418 hk = ngx_array_push(&headers_in);
423 hk->key = header->name;
424 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len);
428 hash.hash = &cmcf->headers_in_hash;
429 hash.key = ngx_hash_key_lc;
431 hash.bucket_size = ngx_align(64, ngx_cacheline_size);
432 hash.name = "headers_in_hash";
433 hash.pool = cf->pool;
434 hash.temp_pool = NULL;
436 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) {
445 ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
449 ngx_uint_t find_config_index, use_rewrite, use_access;
450 ngx_http_handler_pt *h;
451 ngx_http_phase_handler_t *ph;
452 ngx_http_phase_handler_pt checker;
454 cmcf->phase_engine.server_rewrite_index = (ngx_uint_t) -1;
455 cmcf->phase_engine.location_rewrite_index = (ngx_uint_t) -1;
456 find_config_index = 0;
457 use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0;
458 use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0;
460 n = 1 /* find config phase */
461 + use_rewrite /* post rewrite phase */
462 + use_access /* post access phase */
465 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) {
466 n += cmcf->phases[i].handlers.nelts;
469 ph = ngx_pcalloc(cf->pool,
470 n * sizeof(ngx_http_phase_handler_t) + sizeof(void *));
475 cmcf->phase_engine.handlers = ph;
478 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) {
479 h = cmcf->phases[i].handlers.elts;
483 case NGX_HTTP_SERVER_REWRITE_PHASE:
484 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) {
485 cmcf->phase_engine.server_rewrite_index = n;
487 checker = ngx_http_core_rewrite_phase;
491 case NGX_HTTP_FIND_CONFIG_PHASE:
492 find_config_index = n;
494 ph->checker = ngx_http_core_find_config_phase;
500 case NGX_HTTP_REWRITE_PHASE:
501 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) {
502 cmcf->phase_engine.location_rewrite_index = n;
504 checker = ngx_http_core_rewrite_phase;
508 case NGX_HTTP_POST_REWRITE_PHASE:
510 ph->checker = ngx_http_core_post_rewrite_phase;
511 ph->next = find_config_index;
518 case NGX_HTTP_ACCESS_PHASE:
519 checker = ngx_http_core_access_phase;
523 case NGX_HTTP_POST_ACCESS_PHASE:
525 ph->checker = ngx_http_core_post_access_phase;
532 case NGX_HTTP_TRY_FILES_PHASE:
533 if (cmcf->try_files) {
534 ph->checker = ngx_http_core_try_files_phase;
541 case NGX_HTTP_CONTENT_PHASE:
542 checker = ngx_http_core_content_phase;
546 checker = ngx_http_core_generic_phase;
549 n += cmcf->phases[i].handlers.nelts;
551 for (j = cmcf->phases[i].handlers.nelts - 1; j >=0; j--) {
552 ph->checker = checker;
564 ngx_http_merge_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
565 ngx_http_module_t *module, ngx_uint_t ctx_index)
569 ngx_http_conf_ctx_t *ctx, saved;
570 ngx_http_core_loc_conf_t *clcf;
571 ngx_http_core_srv_conf_t **cscfp;
573 cscfp = cmcf->servers.elts;
574 ctx = (ngx_http_conf_ctx_t *) cf->ctx;
578 for (s = 0; s < cmcf->servers.nelts; s++) {
580 /* merge the server{}s' srv_conf's */
582 ctx->srv_conf = cscfp[s]->ctx->srv_conf;
584 if (module->merge_srv_conf) {
585 rv = module->merge_srv_conf(cf, saved.srv_conf[ctx_index],
586 cscfp[s]->ctx->srv_conf[ctx_index]);
587 if (rv != NGX_CONF_OK) {
592 if (module->merge_loc_conf) {
594 /* merge the server{}'s loc_conf */
596 ctx->loc_conf = cscfp[s]->ctx->loc_conf;
598 rv = module->merge_loc_conf(cf, saved.loc_conf[ctx_index],
599 cscfp[s]->ctx->loc_conf[ctx_index]);
600 if (rv != NGX_CONF_OK) {
604 /* merge the locations{}' loc_conf's */
606 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index];
608 rv = ngx_http_merge_locations(cf, clcf->locations,
609 cscfp[s]->ctx->loc_conf,
611 if (rv != NGX_CONF_OK) {
626 ngx_http_merge_locations(ngx_conf_t *cf, ngx_queue_t *locations,
627 void **loc_conf, ngx_http_module_t *module, ngx_uint_t ctx_index)
631 ngx_http_conf_ctx_t *ctx, saved;
632 ngx_http_core_loc_conf_t *clcf;
633 ngx_http_location_queue_t *lq;
635 if (locations == NULL) {
639 ctx = (ngx_http_conf_ctx_t *) cf->ctx;
642 for (q = ngx_queue_head(locations);
643 q != ngx_queue_sentinel(locations);
644 q = ngx_queue_next(q))
646 lq = (ngx_http_location_queue_t *) q;
648 clcf = lq->exact ? lq->exact : lq->inclusive;
649 ctx->loc_conf = clcf->loc_conf;
651 rv = module->merge_loc_conf(cf, loc_conf[ctx_index],
652 clcf->loc_conf[ctx_index]);
653 if (rv != NGX_CONF_OK) {
657 rv = ngx_http_merge_locations(cf, clcf->locations, clcf->loc_conf,
659 if (rv != NGX_CONF_OK) {
671 ngx_http_init_locations(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
672 ngx_http_core_loc_conf_t *pclcf)
675 ngx_queue_t *q, *locations, *named, tail;
676 ngx_http_core_loc_conf_t *clcf;
677 ngx_http_location_queue_t *lq;
678 ngx_http_core_loc_conf_t **clcfp;
684 locations = pclcf->locations;
686 if (locations == NULL) {
690 ngx_queue_sort(locations, ngx_http_cmp_locations);
699 for (q = ngx_queue_head(locations);
700 q != ngx_queue_sentinel(locations);
701 q = ngx_queue_next(q))
703 lq = (ngx_http_location_queue_t *) q;
705 clcf = lq->exact ? lq->exact : lq->inclusive;
707 if (ngx_http_init_locations(cf, NULL, clcf) != NGX_OK) {
740 if (q != ngx_queue_sentinel(locations)) {
741 ngx_queue_split(locations, q, &tail);
745 clcfp = ngx_palloc(cf->pool,
746 (n + 1) * sizeof(ngx_http_core_loc_conf_t *));
751 cscf->named_locations = clcfp;
754 q != ngx_queue_sentinel(locations);
755 q = ngx_queue_next(q))
757 lq = (ngx_http_location_queue_t *) q;
759 *(clcfp++) = lq->exact;
764 ngx_queue_split(locations, named, &tail);
771 clcfp = ngx_palloc(cf->pool,
772 (r + 1) * sizeof(ngx_http_core_loc_conf_t *));
777 pclcf->regex_locations = clcfp;
780 q != ngx_queue_sentinel(locations);
781 q = ngx_queue_next(q))
783 lq = (ngx_http_location_queue_t *) q;
785 *(clcfp++) = lq->exact;
790 ngx_queue_split(locations, regex, &tail);
800 ngx_http_init_static_location_trees(ngx_conf_t *cf,
801 ngx_http_core_loc_conf_t *pclcf)
803 ngx_queue_t *q, *locations;
804 ngx_http_core_loc_conf_t *clcf;
805 ngx_http_location_queue_t *lq;
807 locations = pclcf->locations;
809 if (locations == NULL) {
813 if (ngx_queue_empty(locations)) {
817 for (q = ngx_queue_head(locations);
818 q != ngx_queue_sentinel(locations);
819 q = ngx_queue_next(q))
821 lq = (ngx_http_location_queue_t *) q;
823 clcf = lq->exact ? lq->exact : lq->inclusive;
825 if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) {
830 if (ngx_http_join_exact_locations(cf, locations) != NGX_OK) {
834 ngx_http_create_locations_list(locations, ngx_queue_head(locations));
836 pclcf->static_locations = ngx_http_create_locations_tree(cf, locations, 0);
837 if (pclcf->static_locations == NULL) {
846 ngx_http_add_location(ngx_conf_t *cf, ngx_queue_t **locations,
847 ngx_http_core_loc_conf_t *clcf)
849 ngx_http_location_queue_t *lq;
851 if (*locations == NULL) {
852 *locations = ngx_palloc(cf->temp_pool,
853 sizeof(ngx_http_location_queue_t));
854 if (*locations == NULL) {
858 ngx_queue_init(*locations);
861 lq = ngx_palloc(cf->temp_pool, sizeof(ngx_http_location_queue_t));
866 if (clcf->exact_match
870 || clcf->named || clcf->noname)
873 lq->inclusive = NULL;
877 lq->inclusive = clcf;
880 lq->name = &clcf->name;
881 lq->file_name = cf->conf_file->file.name.data;
882 lq->line = cf->conf_file->line;
884 ngx_queue_init(&lq->list);
886 ngx_queue_insert_tail(*locations, &lq->queue);
893 ngx_http_cmp_locations(const ngx_queue_t *one, const ngx_queue_t *two)
896 ngx_http_core_loc_conf_t *first, *second;
897 ngx_http_location_queue_t *lq1, *lq2;
899 lq1 = (ngx_http_location_queue_t *) one;
900 lq2 = (ngx_http_location_queue_t *) two;
902 first = lq1->exact ? lq1->exact : lq1->inclusive;
903 second = lq2->exact ? lq2->exact : lq2->inclusive;
905 if (first->noname && !second->noname) {
906 /* shift no named locations to the end */
910 if (!first->noname && second->noname) {
911 /* shift no named locations to the end */
915 if (first->noname || second->noname) {
916 /* do not sort no named locations */
920 if (first->named && !second->named) {
921 /* shift named locations to the end */
925 if (!first->named && second->named) {
926 /* shift named locations to the end */
930 if (first->named && second->named) {
931 return ngx_strcmp(first->name.data, second->name.data);
936 if (first->regex && !second->regex) {
937 /* shift the regex matches to the end */
941 if (!first->regex && second->regex) {
942 /* shift the regex matches to the end */
946 if (first->regex || second->regex) {
947 /* do not sort the regex matches */
953 rc = ngx_filename_cmp(first->name.data, second->name.data,
954 ngx_min(first->name.len, second->name.len) + 1);
956 if (rc == 0 && !first->exact_match && second->exact_match) {
957 /* an exact match must be before the same inclusive one */
966 ngx_http_join_exact_locations(ngx_conf_t *cf, ngx_queue_t *locations)
969 ngx_http_location_queue_t *lq, *lx;
971 q = ngx_queue_head(locations);
973 while (q != ngx_queue_last(locations)) {
975 x = ngx_queue_next(q);
977 lq = (ngx_http_location_queue_t *) q;
978 lx = (ngx_http_location_queue_t *) x;
980 if (lq->name->len == lx->name->len
981 && ngx_filename_cmp(lq->name->data, lx->name->data, lx->name->len)
984 if ((lq->exact && lx->exact) || (lq->inclusive && lx->inclusive)) {
985 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
986 "duplicate location \"%V\" in %s:%ui",
987 lx->name, lx->file_name, lx->line);
992 lq->inclusive = lx->inclusive;
999 q = ngx_queue_next(q);
1007 ngx_http_create_locations_list(ngx_queue_t *locations, ngx_queue_t *q)
1011 ngx_queue_t *x, tail;
1012 ngx_http_location_queue_t *lq, *lx;
1014 if (q == ngx_queue_last(locations)) {
1018 lq = (ngx_http_location_queue_t *) q;
1020 if (lq->inclusive == NULL) {
1021 ngx_http_create_locations_list(locations, ngx_queue_next(q));
1025 len = lq->name->len;
1026 name = lq->name->data;
1028 for (x = ngx_queue_next(q);
1029 x != ngx_queue_sentinel(locations);
1030 x = ngx_queue_next(x))
1032 lx = (ngx_http_location_queue_t *) x;
1034 if (len > lx->name->len
1035 || ngx_filename_cmp(name, lx->name->data, len) != 0)
1041 q = ngx_queue_next(q);
1044 ngx_http_create_locations_list(locations, x);
1048 ngx_queue_split(locations, q, &tail);
1049 ngx_queue_add(&lq->list, &tail);
1051 if (x == ngx_queue_sentinel(locations)) {
1052 ngx_http_create_locations_list(&lq->list, ngx_queue_head(&lq->list));
1056 ngx_queue_split(&lq->list, x, &tail);
1057 ngx_queue_add(locations, &tail);
1059 ngx_http_create_locations_list(&lq->list, ngx_queue_head(&lq->list));
1061 ngx_http_create_locations_list(locations, x);
1066 * to keep cache locality for left leaf nodes, allocate nodes in following
1067 * order: node, left subtree, right subtree, inclusive subtree
1070 static ngx_http_location_tree_node_t *
1071 ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations,
1075 ngx_queue_t *q, tail;
1076 ngx_http_location_queue_t *lq;
1077 ngx_http_location_tree_node_t *node;
1079 q = ngx_queue_middle(locations);
1081 lq = (ngx_http_location_queue_t *) q;
1082 len = lq->name->len - prefix;
1084 node = ngx_palloc(cf->pool,
1085 offsetof(ngx_http_location_tree_node_t, name) + len);
1093 node->exact = lq->exact;
1094 node->inclusive = lq->inclusive;
1096 node->auto_redirect = (u_char) ((lq->exact && lq->exact->auto_redirect)
1097 || (lq->inclusive && lq->inclusive->auto_redirect));
1099 node->len = (u_char) len;
1100 ngx_memcpy(node->name, &lq->name->data[prefix], len);
1102 ngx_queue_split(locations, q, &tail);
1104 if (ngx_queue_empty(locations)) {
1106 * ngx_queue_split() insures that if left part is empty,
1107 * then right one is empty too
1112 node->left = ngx_http_create_locations_tree(cf, locations, prefix);
1113 if (node->left == NULL) {
1117 ngx_queue_remove(q);
1119 if (ngx_queue_empty(&tail)) {
1123 node->right = ngx_http_create_locations_tree(cf, &tail, prefix);
1124 if (node->right == NULL) {
1130 if (ngx_queue_empty(&lq->list)) {
1134 node->tree = ngx_http_create_locations_tree(cf, &lq->list, prefix + len);
1135 if (node->tree == NULL) {
1144 ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1145 ngx_http_listen_opt_t *lsopt)
1149 struct sockaddr *sa;
1150 ngx_http_conf_port_t *port;
1151 ngx_http_core_main_conf_t *cmcf;
1153 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
1155 if (cmcf->ports == NULL) {
1156 cmcf->ports = ngx_array_create(cf->temp_pool, 2,
1157 sizeof(ngx_http_conf_port_t));
1158 if (cmcf->ports == NULL) {
1163 sa = &lsopt->sockaddr.sockaddr;
1164 p = ngx_inet_get_port(sa);
1166 port = cmcf->ports->elts;
1167 for (i = 0; i < cmcf->ports->nelts; i++) {
1169 if (p != port[i].port || sa->sa_family != port[i].family) {
1173 /* a port is already in the port list */
1175 return ngx_http_add_addresses(cf, cscf, &port[i], lsopt);
1178 /* add a port to the port list */
1180 port = ngx_array_push(cmcf->ports);
1185 port->family = sa->sa_family;
1187 port->addrs.elts = NULL;
1189 return ngx_http_add_address(cf, cscf, port, lsopt);
1194 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1195 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
1197 ngx_uint_t i, default_server, proxy_protocol;
1198 ngx_http_conf_addr_t *addr;
1207 * we cannot compare whole sockaddr struct's as kernel
1208 * may fill some fields in inherited sockaddr struct's
1211 addr = port->addrs.elts;
1213 for (i = 0; i < port->addrs.nelts; i++) {
1215 if (ngx_cmp_sockaddr(&lsopt->sockaddr.sockaddr, lsopt->socklen,
1216 &addr[i].opt.sockaddr.sockaddr,
1217 addr[i].opt.socklen, 0)
1223 /* the address is already in the address list */
1225 if (ngx_http_add_server(cf, cscf, &addr[i]) != NGX_OK) {
1229 /* preserve default_server bit during listen options overwriting */
1230 default_server = addr[i].opt.default_server;
1232 proxy_protocol = lsopt->proxy_protocol || addr[i].opt.proxy_protocol;
1235 ssl = lsopt->ssl || addr[i].opt.ssl;
1238 http2 = lsopt->http2 || addr[i].opt.http2;
1243 if (addr[i].opt.set) {
1244 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1245 "duplicate listen options for %s", addr[i].opt.addr);
1249 addr[i].opt = *lsopt;
1252 /* check the duplicate "default" server for this address:port */
1254 if (lsopt->default_server) {
1256 if (default_server) {
1257 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1258 "a duplicate default server for %s", addr[i].opt.addr);
1263 addr[i].default_server = cscf;
1266 addr[i].opt.default_server = default_server;
1267 addr[i].opt.proxy_protocol = proxy_protocol;
1269 addr[i].opt.ssl = ssl;
1272 addr[i].opt.http2 = http2;
1278 /* add the address to the addresses list that bound to this port */
1280 return ngx_http_add_address(cf, cscf, port, lsopt);
1285 * add the server address, the server names and the server core module
1286 * configurations to the port list
1290 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1291 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
1293 ngx_http_conf_addr_t *addr;
1295 if (port->addrs.elts == NULL) {
1296 if (ngx_array_init(&port->addrs, cf->temp_pool, 4,
1297 sizeof(ngx_http_conf_addr_t))
1304 #if (NGX_HTTP_V2 && NGX_HTTP_SSL \
1305 && !defined TLSEXT_TYPE_application_layer_protocol_negotiation \
1306 && !defined TLSEXT_TYPE_next_proto_neg)
1308 if (lsopt->http2 && lsopt->ssl) {
1309 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1310 "nginx was built with OpenSSL that lacks ALPN "
1311 "and NPN support, HTTP/2 is not enabled for %s",
1317 addr = ngx_array_push(&port->addrs);
1323 addr->hash.buckets = NULL;
1324 addr->hash.size = 0;
1325 addr->wc_head = NULL;
1326 addr->wc_tail = NULL;
1331 addr->default_server = cscf;
1332 addr->servers.elts = NULL;
1334 return ngx_http_add_server(cf, cscf, addr);
1338 /* add the server core module configuration to the address:port */
1341 ngx_http_add_server(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1342 ngx_http_conf_addr_t *addr)
1345 ngx_http_core_srv_conf_t **server;
1347 if (addr->servers.elts == NULL) {
1348 if (ngx_array_init(&addr->servers, cf->temp_pool, 4,
1349 sizeof(ngx_http_core_srv_conf_t *))
1356 server = addr->servers.elts;
1357 for (i = 0; i < addr->servers.nelts; i++) {
1358 if (server[i] == cscf) {
1359 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1360 "a duplicate listen %s", addr->opt.addr);
1366 server = ngx_array_push(&addr->servers);
1367 if (server == NULL) {
1378 ngx_http_optimize_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
1382 ngx_http_conf_port_t *port;
1383 ngx_http_conf_addr_t *addr;
1385 if (ports == NULL) {
1390 for (p = 0; p < ports->nelts; p++) {
1392 ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts,
1393 sizeof(ngx_http_conf_addr_t), ngx_http_cmp_conf_addrs);
1396 * check whether all name-based servers have the same
1397 * configuration as a default server for given address:port
1400 addr = port[p].addrs.elts;
1401 for (a = 0; a < port[p].addrs.nelts; a++) {
1403 if (addr[a].servers.nelts > 1
1405 || addr[a].default_server->captures
1409 if (ngx_http_server_names(cf, cmcf, &addr[a]) != NGX_OK) {
1415 if (ngx_http_init_listening(cf, &port[p]) != NGX_OK) {
1425 ngx_http_server_names(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
1426 ngx_http_conf_addr_t *addr)
1430 ngx_hash_init_t hash;
1431 ngx_hash_keys_arrays_t ha;
1432 ngx_http_server_name_t *name;
1433 ngx_http_core_srv_conf_t **cscfp;
1435 ngx_uint_t regex, i;
1440 ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t));
1442 ha.temp_pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, cf->log);
1443 if (ha.temp_pool == NULL) {
1449 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) {
1453 cscfp = addr->servers.elts;
1455 for (s = 0; s < addr->servers.nelts; s++) {
1457 name = cscfp[s]->server_names.elts;
1459 for (n = 0; n < cscfp[s]->server_names.nelts; n++) {
1462 if (name[n].regex) {
1468 rc = ngx_hash_add_key(&ha, &name[n].name, name[n].server,
1469 NGX_HASH_WILDCARD_KEY);
1471 if (rc == NGX_ERROR) {
1475 if (rc == NGX_DECLINED) {
1476 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1477 "invalid server name or wildcard \"%V\" on %s",
1478 &name[n].name, addr->opt.addr);
1482 if (rc == NGX_BUSY) {
1483 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
1484 "conflicting server name \"%V\" on %s, ignored",
1485 &name[n].name, addr->opt.addr);
1490 hash.key = ngx_hash_key_lc;
1491 hash.max_size = cmcf->server_names_hash_max_size;
1492 hash.bucket_size = cmcf->server_names_hash_bucket_size;
1493 hash.name = "server_names_hash";
1494 hash.pool = cf->pool;
1496 if (ha.keys.nelts) {
1497 hash.hash = &addr->hash;
1498 hash.temp_pool = NULL;
1500 if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK) {
1505 if (ha.dns_wc_head.nelts) {
1507 ngx_qsort(ha.dns_wc_head.elts, (size_t) ha.dns_wc_head.nelts,
1508 sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards);
1511 hash.temp_pool = ha.temp_pool;
1513 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts,
1514 ha.dns_wc_head.nelts)
1520 addr->wc_head = (ngx_hash_wildcard_t *) hash.hash;
1523 if (ha.dns_wc_tail.nelts) {
1525 ngx_qsort(ha.dns_wc_tail.elts, (size_t) ha.dns_wc_tail.nelts,
1526 sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards);
1529 hash.temp_pool = ha.temp_pool;
1531 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts,
1532 ha.dns_wc_tail.nelts)
1538 addr->wc_tail = (ngx_hash_wildcard_t *) hash.hash;
1541 ngx_destroy_pool(ha.temp_pool);
1549 addr->nregex = regex;
1550 addr->regex = ngx_palloc(cf->pool, regex * sizeof(ngx_http_server_name_t));
1551 if (addr->regex == NULL) {
1557 for (s = 0; s < addr->servers.nelts; s++) {
1559 name = cscfp[s]->server_names.elts;
1561 for (n = 0; n < cscfp[s]->server_names.nelts; n++) {
1562 if (name[n].regex) {
1563 addr->regex[i++] = name[n];
1574 ngx_destroy_pool(ha.temp_pool);
1581 ngx_http_cmp_conf_addrs(const void *one, const void *two)
1583 ngx_http_conf_addr_t *first, *second;
1585 first = (ngx_http_conf_addr_t *) one;
1586 second = (ngx_http_conf_addr_t *) two;
1588 if (first->opt.wildcard) {
1589 /* a wildcard address must be the last resort, shift it to the end */
1593 if (second->opt.wildcard) {
1594 /* a wildcard address must be the last resort, shift it to the end */
1598 if (first->opt.bind && !second->opt.bind) {
1599 /* shift explicit bind()ed addresses to the start */
1603 if (!first->opt.bind && second->opt.bind) {
1604 /* shift explicit bind()ed addresses to the start */
1608 /* do not sort by default */
1614 static int ngx_libc_cdecl
1615 ngx_http_cmp_dns_wildcards(const void *one, const void *two)
1617 ngx_hash_key_t *first, *second;
1619 first = (ngx_hash_key_t *) one;
1620 second = (ngx_hash_key_t *) two;
1622 return ngx_dns_strcmp(first->key.data, second->key.data);
1627 ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
1629 ngx_uint_t i, last, bind_wildcard;
1630 ngx_listening_t *ls;
1631 ngx_http_port_t *hport;
1632 ngx_http_conf_addr_t *addr;
1634 addr = port->addrs.elts;
1635 last = port->addrs.nelts;
1638 * If there is a binding to an "*:port" then we need to bind() to
1639 * the "*:port" only and ignore other implicit bindings. The bindings
1640 * have been already sorted: explicit bindings are on the start, then
1641 * implicit bindings go, and wildcard binding is in the end.
1644 if (addr[last - 1].opt.wildcard) {
1645 addr[last - 1].opt.bind = 1;
1656 if (bind_wildcard && !addr[i].opt.bind) {
1661 ls = ngx_http_add_listening(cf, &addr[i]);
1666 hport = ngx_pcalloc(cf->pool, sizeof(ngx_http_port_t));
1667 if (hport == NULL) {
1671 ls->servers = hport;
1673 hport->naddrs = i + 1;
1675 switch (ls->sockaddr->sa_family) {
1677 #if (NGX_HAVE_INET6)
1679 if (ngx_http_add_addrs6(cf, hport, addr) != NGX_OK) {
1684 default: /* AF_INET */
1685 if (ngx_http_add_addrs(cf, hport, addr) != NGX_OK) {
1691 if (ngx_clone_listening(cf, ls) != NGX_OK) {
1703 static ngx_listening_t *
1704 ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)
1706 ngx_listening_t *ls;
1707 ngx_http_core_loc_conf_t *clcf;
1708 ngx_http_core_srv_conf_t *cscf;
1710 ls = ngx_create_listening(cf, &addr->opt.sockaddr.sockaddr,
1718 ls->handler = ngx_http_init_connection;
1720 cscf = addr->default_server;
1721 ls->pool_size = cscf->connection_pool_size;
1722 ls->post_accept_timeout = cscf->client_header_timeout;
1724 clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
1726 ls->logp = clcf->error_log;
1727 ls->log.data = &ls->addr_text;
1728 ls->log.handler = ngx_accept_log_error;
1732 ngx_iocp_conf_t *iocpcf = NULL;
1734 if (ngx_get_conf(cf->cycle->conf_ctx, ngx_events_module)) {
1735 iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
1737 if (iocpcf && iocpcf->acceptex_read) {
1738 ls->post_accept_buffer_size = cscf->client_header_buffer_size;
1743 ls->backlog = addr->opt.backlog;
1744 ls->rcvbuf = addr->opt.rcvbuf;
1745 ls->sndbuf = addr->opt.sndbuf;
1747 ls->keepalive = addr->opt.so_keepalive;
1748 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
1749 ls->keepidle = addr->opt.tcp_keepidle;
1750 ls->keepintvl = addr->opt.tcp_keepintvl;
1751 ls->keepcnt = addr->opt.tcp_keepcnt;
1754 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
1755 ls->accept_filter = addr->opt.accept_filter;
1758 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
1759 ls->deferred_accept = addr->opt.deferred_accept;
1762 #if (NGX_HAVE_INET6)
1763 ls->ipv6only = addr->opt.ipv6only;
1766 #if (NGX_HAVE_SETFIB)
1767 ls->setfib = addr->opt.setfib;
1770 #if (NGX_HAVE_TCP_FASTOPEN)
1771 ls->fastopen = addr->opt.fastopen;
1774 #if (NGX_HAVE_REUSEPORT)
1775 ls->reuseport = addr->opt.reuseport;
1783 ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport,
1784 ngx_http_conf_addr_t *addr)
1787 ngx_http_in_addr_t *addrs;
1788 struct sockaddr_in *sin;
1789 ngx_http_virtual_names_t *vn;
1791 hport->addrs = ngx_pcalloc(cf->pool,
1792 hport->naddrs * sizeof(ngx_http_in_addr_t));
1793 if (hport->addrs == NULL) {
1797 addrs = hport->addrs;
1799 for (i = 0; i < hport->naddrs; i++) {
1801 sin = &addr[i].opt.sockaddr.sockaddr_in;
1802 addrs[i].addr = sin->sin_addr.s_addr;
1803 addrs[i].conf.default_server = addr[i].default_server;
1805 addrs[i].conf.ssl = addr[i].opt.ssl;
1808 addrs[i].conf.http2 = addr[i].opt.http2;
1810 addrs[i].conf.proxy_protocol = addr[i].opt.proxy_protocol;
1812 if (addr[i].hash.buckets == NULL
1813 && (addr[i].wc_head == NULL
1814 || addr[i].wc_head->hash.buckets == NULL)
1815 && (addr[i].wc_tail == NULL
1816 || addr[i].wc_tail->hash.buckets == NULL)
1818 && addr[i].nregex == 0
1825 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
1830 addrs[i].conf.virtual_names = vn;
1832 vn->names.hash = addr[i].hash;
1833 vn->names.wc_head = addr[i].wc_head;
1834 vn->names.wc_tail = addr[i].wc_tail;
1836 vn->nregex = addr[i].nregex;
1837 vn->regex = addr[i].regex;
1845 #if (NGX_HAVE_INET6)
1848 ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport,
1849 ngx_http_conf_addr_t *addr)
1852 ngx_http_in6_addr_t *addrs6;
1853 struct sockaddr_in6 *sin6;
1854 ngx_http_virtual_names_t *vn;
1856 hport->addrs = ngx_pcalloc(cf->pool,
1857 hport->naddrs * sizeof(ngx_http_in6_addr_t));
1858 if (hport->addrs == NULL) {
1862 addrs6 = hport->addrs;
1864 for (i = 0; i < hport->naddrs; i++) {
1866 sin6 = &addr[i].opt.sockaddr.sockaddr_in6;
1867 addrs6[i].addr6 = sin6->sin6_addr;
1868 addrs6[i].conf.default_server = addr[i].default_server;
1870 addrs6[i].conf.ssl = addr[i].opt.ssl;
1873 addrs6[i].conf.http2 = addr[i].opt.http2;
1875 addrs6[i].conf.proxy_protocol = addr[i].opt.proxy_protocol;
1877 if (addr[i].hash.buckets == NULL
1878 && (addr[i].wc_head == NULL
1879 || addr[i].wc_head->hash.buckets == NULL)
1880 && (addr[i].wc_tail == NULL
1881 || addr[i].wc_tail->hash.buckets == NULL)
1883 && addr[i].nregex == 0
1890 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
1895 addrs6[i].conf.virtual_names = vn;
1897 vn->names.hash = addr[i].hash;
1898 vn->names.wc_head = addr[i].wc_head;
1899 vn->names.wc_tail = addr[i].wc_tail;
1901 vn->nregex = addr[i].nregex;
1902 vn->regex = addr[i].regex;
1913 ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1917 ngx_array_t **types;
1918 ngx_str_t *value, *default_type;
1919 ngx_uint_t i, n, hash;
1920 ngx_hash_key_t *type;
1922 types = (ngx_array_t **) (p + cmd->offset);
1924 if (*types == (void *) -1) {
1928 default_type = cmd->post;
1930 if (*types == NULL) {
1931 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t));
1932 if (*types == NULL) {
1933 return NGX_CONF_ERROR;
1937 type = ngx_array_push(*types);
1939 return NGX_CONF_ERROR;
1942 type->key = *default_type;
1943 type->key_hash = ngx_hash_key(default_type->data,
1945 type->value = (void *) 4;
1949 value = cf->args->elts;
1951 for (i = 1; i < cf->args->nelts; i++) {
1953 if (value[i].len == 1 && value[i].data[0] == '*') {
1954 *types = (void *) -1;
1958 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
1959 value[i].data[value[i].len] = '\0';
1961 type = (*types)->elts;
1962 for (n = 0; n < (*types)->nelts; n++) {
1964 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
1965 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1966 "duplicate MIME type \"%V\"", &value[i]);
1971 type = ngx_array_push(*types);
1973 return NGX_CONF_ERROR;
1976 type->key = value[i];
1977 type->key_hash = hash;
1978 type->value = (void *) 4;
1990 ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t **keys, ngx_hash_t *types_hash,
1991 ngx_array_t **prev_keys, ngx_hash_t *prev_types_hash,
1992 ngx_str_t *default_types)
1994 ngx_hash_init_t hash;
1998 if (*keys == (void *) -1) {
2002 hash.hash = types_hash;
2004 hash.max_size = 2048;
2005 hash.bucket_size = 64;
2006 hash.name = "test_types_hash";
2007 hash.pool = cf->pool;
2008 hash.temp_pool = NULL;
2010 if (ngx_hash_init(&hash, (*keys)->elts, (*keys)->nelts) != NGX_OK) {
2011 return NGX_CONF_ERROR;
2017 if (prev_types_hash->buckets == NULL) {
2019 if (*prev_keys == NULL) {
2021 if (ngx_http_set_default_types(cf, prev_keys, default_types)
2024 return NGX_CONF_ERROR;
2027 } else if (*prev_keys == (void *) -1) {
2032 hash.hash = prev_types_hash;
2034 hash.max_size = 2048;
2035 hash.bucket_size = 64;
2036 hash.name = "test_types_hash";
2037 hash.pool = cf->pool;
2038 hash.temp_pool = NULL;
2040 if (ngx_hash_init(&hash, (*prev_keys)->elts, (*prev_keys)->nelts)
2043 return NGX_CONF_ERROR;
2047 *types_hash = *prev_types_hash;
2055 ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types,
2056 ngx_str_t *default_type)
2058 ngx_hash_key_t *type;
2060 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t));
2061 if (*types == NULL) {
2065 while (default_type->len) {
2067 type = ngx_array_push(*types);
2072 type->key = *default_type;
2073 type->key_hash = ngx_hash_key(default_type->data,
2075 type->value = (void *) 4;