📄 ngx_http.c
字号:
continue; } module = ngx_modules[m]->ctx; mi = ngx_modules[m]->ctx_index; if (module->postconfiguration) { if (module->postconfiguration(cf) != NGX_OK) { return NGX_CONF_ERROR; } } } if (ngx_http_variables_init_vars(cf) != NGX_OK) { return NGX_CONF_ERROR; } /* * http{}'s cf->ctx was needed while the configuration merging * and in postconfiguration process */ *cf = pcf; cmcf->phase_engine.server_rewrite_index = (ngx_uint_t) -1; cmcf->phase_engine.location_rewrite_index = (ngx_uint_t) -1; find_config_index = 0; use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0; use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0; n = use_rewrite + use_access + 1; /* find config phase */ for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { n += cmcf->phases[i].handlers.nelts; } ph = ngx_pcalloc(cf->pool, n * sizeof(ngx_http_phase_handler_t) + sizeof(void *)); if (ph == NULL) { return NGX_CONF_ERROR; } cmcf->phase_engine.handlers = ph; n = 0; for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { h = cmcf->phases[i].handlers.elts; switch (i) { case NGX_HTTP_SERVER_REWRITE_PHASE: if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) { cmcf->phase_engine.server_rewrite_index = n; } checker = ngx_http_core_generic_phase; break; case NGX_HTTP_FIND_CONFIG_PHASE: find_config_index = n; ph->checker = ngx_http_core_find_config_phase; n++; ph++; continue; case NGX_HTTP_REWRITE_PHASE: if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) { cmcf->phase_engine.location_rewrite_index = n; } checker = ngx_http_core_generic_phase; break; case NGX_HTTP_POST_REWRITE_PHASE: if (use_rewrite) { ph->checker = ngx_http_core_post_rewrite_phase; ph->next = find_config_index; n++; ph++; } continue; case NGX_HTTP_ACCESS_PHASE: checker = ngx_http_core_access_phase; n++; break; case NGX_HTTP_POST_ACCESS_PHASE: if (use_access) { ph->checker = ngx_http_core_post_access_phase; ph->next = n; ph++; } continue; case NGX_HTTP_CONTENT_PHASE: checker = ngx_http_core_content_phase; break; default: checker = ngx_http_core_generic_phase; } n += cmcf->phases[i].handlers.nelts; for (j = cmcf->phases[i].handlers.nelts - 1; j >=0; j--) { ph->checker = checker; ph->handler = h[j]; ph->next = n; ph++; } } /* * create the lists of ports, addresses and server names * to quickly find the server core module configuration at run-time */ if (ngx_array_init(&in_ports, cf->temp_pool, 2, sizeof(ngx_http_conf_in_port_t)) != NGX_OK) { return NGX_CONF_ERROR; } /* "server" directives */ cscfp = cmcf->servers.elts; for (s = 0; s < cmcf->servers.nelts; s++) { /* "listen" directives */ lscf = cscfp[s]->listen.elts; for (l = 0; l < cscfp[s]->listen.nelts; l++) { /* AF_INET only */ in_port = in_ports.elts; for (p = 0; p < in_ports.nelts; p++) { if (lscf[l].port != in_port[p].port) { continue; } /* the port is already in the port list */ in_addr = in_port[p].addrs.elts; for (a = 0; a < in_port[p].addrs.nelts; a++) { if (lscf[l].addr != in_addr[a].addr) { continue; } /* the address is already in the address list */ if (ngx_http_add_names(cf, &in_addr[a], cscfp[s]) != NGX_OK) { return NGX_CONF_ERROR; } /* * check the duplicate "default" server * for this address:port */ if (lscf[l].conf.default_server) { if (in_addr[a].default_server) { ngx_log_error(NGX_LOG_ERR, cf->log, 0, "the duplicate default server in %s:%ui", lscf[l].file_name, lscf[l].line); return NGX_CONF_ERROR; } in_addr[a].core_srv_conf = cscfp[s]; in_addr[a].default_server = 1; } goto found; } /* * add the address to the addresses list that * bound to this port */ if (ngx_http_add_address(cf, &in_port[p], &lscf[l], cscfp[s]) != NGX_OK) { return NGX_CONF_ERROR; } goto found; } /* add the port to the in_port list */ in_port = ngx_array_push(&in_ports); if (in_port == NULL) { return NGX_CONF_ERROR; } in_port->port = lscf[l].port; in_port->addrs.elts = NULL; if (ngx_http_add_address(cf, in_port, &lscf[l], cscfp[s]) != NGX_OK) { return NGX_CONF_ERROR; } found: continue; } } /* optimize the lists of ports, addresses and server names */ /* AF_INET only */ in_port = in_ports.elts; for (p = 0; p < in_ports.nelts; p++) { ngx_sort(in_port[p].addrs.elts, (size_t) in_port[p].addrs.nelts, sizeof(ngx_http_conf_in_addr_t), ngx_http_cmp_conf_in_addrs); /* * check whether all name-based servers have the same configuraiton * as the default server, * or some servers disable optimizing the server names */ in_addr = in_port[p].addrs.elts; for (a = 0; a < in_port[p].addrs.nelts; a++) { name = in_addr[a].names.elts; for (s = 0; s < in_addr[a].names.nelts; s++) { if (in_addr[a].core_srv_conf != name[s].core_srv_conf || name[s].core_srv_conf->optimize_server_names == 0) { goto virtual_names; } } /* * if all name-based servers have the same configuration * as the default server, * and no servers disable optimizing the server names * then we do not need to check them at run-time at all */ in_addr[a].names.nelts = 0; continue; virtual_names: ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t)); ha.temp_pool = ngx_create_pool(16384, cf->log); if (ha.temp_pool == NULL) { return NGX_CONF_ERROR; } ha.pool = cf->pool; if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { ngx_destroy_pool(ha.temp_pool); return NGX_CONF_ERROR; }#if (NGX_PCRE) regex = 0;#endif name = in_addr[a].names.elts; for (s = 0; s < in_addr[a].names.nelts; s++) {#if (NGX_PCRE) if (name[s].regex) { regex++; continue; }#endif rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, NGX_HASH_WILDCARD_KEY); if (rc == NGX_ERROR) { return NGX_CONF_ERROR; } if (rc == NGX_DECLINED) { ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "invalid server name or wildcard \"%V\" on %s", &name[s].name, in_addr[a].listen_conf->addr); return NGX_CONF_ERROR; } if (rc == NGX_BUSY) { ngx_log_error(NGX_LOG_WARN, cf->log, 0, "conflicting server name \"%V\" on %s, ignored", &name[s].name, in_addr[a].listen_conf->addr); } } hash.key = ngx_hash_key_lc; hash.max_size = cmcf->server_names_hash_max_size; hash.bucket_size = cmcf->server_names_hash_bucket_size; hash.name = "server_names_hash"; hash.pool = cf->pool; if (ha.keys.nelts) { hash.hash = &in_addr[a].hash; hash.temp_pool = NULL; if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK) { ngx_destroy_pool(ha.temp_pool); return NGX_CONF_ERROR; } } if (ha.dns_wc_head.nelts) { ngx_qsort(ha.dns_wc_head.elts, (size_t) ha.dns_wc_head.nelts, sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards); hash.hash = NULL; hash.temp_pool = ha.temp_pool; if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts, ha.dns_wc_head.nelts) != NGX_OK) { ngx_destroy_pool(ha.temp_pool); return NGX_CONF_ERROR; } in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash; } if (ha.dns_wc_tail.nelts) { ngx_qsort(ha.dns_wc_tail.elts, (size_t) ha.dns_wc_tail.nelts, sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards); hash.hash = NULL; hash.temp_pool = ha.temp_pool; if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts, ha.dns_wc_tail.nelts) != NGX_OK) { ngx_destroy_pool(ha.temp_pool); return NGX_CONF_ERROR; } in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash; } ngx_destroy_pool(ha.temp_pool);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -