diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 25adec28f..a404dd81b 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -2427,7 +2427,9 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) ngx_uint_t i; ngx_conf_t pcf; ngx_http_module_t *module; + struct sockaddr_in *sin; ngx_http_conf_ctx_t *ctx, *http_ctx; + ngx_http_listen_opt_t lsopt; ngx_http_core_srv_conf_t *cscf, **cscfp; ngx_http_core_main_conf_t *cmcf; @@ -2506,6 +2508,37 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) *cf = pcf; + if (rv == NGX_CONF_OK && !cscf->listen) { + ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); + + sin = &lsopt.u.sockaddr_in; + + sin->sin_family = AF_INET; +#if (NGX_WIN32) + sin->sin_port = htons(80); +#else + sin->sin_port = htons((getuid() == 0) ? 80 : 8000); +#endif + sin->sin_addr.s_addr = INADDR_ANY; + + lsopt.socklen = sizeof(struct sockaddr_in); + + lsopt.backlog = NGX_LISTEN_BACKLOG; + lsopt.rcvbuf = -1; + lsopt.sndbuf = -1; +#if (NGX_HAVE_SETFIB) + lsopt.setfib = -1; +#endif + lsopt.wildcard = 1; + + (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, + NGX_SOCKADDR_STRLEN, 1); + + if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) { + return NGX_CONF_ERROR; + } + } + return rv; } @@ -2946,8 +2979,6 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) ngx_http_core_srv_conf_t *prev = parent; ngx_http_core_srv_conf_t *conf = child; - struct sockaddr_in *sin; - ngx_http_listen_opt_t lsopt; ngx_http_server_name_t *sn; /* TODO: it does not merge, it inits only */ @@ -2979,37 +3010,6 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_value(conf->underscores_in_headers, prev->underscores_in_headers, 0); - if (!conf->listen) { - ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); - - sin = &lsopt.u.sockaddr_in; - - sin->sin_family = AF_INET; -#if (NGX_WIN32) - sin->sin_port = htons(80); -#else - sin->sin_port = htons((getuid() == 0) ? 80 : 8000); -#endif - sin->sin_addr.s_addr = INADDR_ANY; - - lsopt.socklen = sizeof(struct sockaddr_in); - - lsopt.backlog = NGX_LISTEN_BACKLOG; - lsopt.rcvbuf = -1; - lsopt.sndbuf = -1; -#if (NGX_HAVE_SETFIB) - lsopt.setfib = -1; -#endif - lsopt.wildcard = 1; - - (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, - NGX_SOCKADDR_STRLEN, 1); - - if (ngx_http_add_listen(cf, conf, &lsopt) != NGX_OK) { - return NGX_CONF_ERROR; - } - } - if (conf->server_name.data == NULL) { ngx_str_set(&conf->server_name, "");