From 7087d5d72ae14bdabf56a956e20ea440b85e2d90 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 11 Oct 2010 18:48:18 +0000 Subject: [PATCH] add default listen port at the end of server block parsing instead of merge phase: otherwise the first server without an listen directive did not become the default server if there was no explicit default server; the bug has been introduced in r3218 --- src/http/ngx_http_core_module.c | 66 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) 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, "");