# HG changeset patch # User Igor Sysoev # Date 1286822898 0 # Node ID 2902fc8487aebd2f1615042a78bd3f86f868417b # Parent 5ceb0f62423322aaa19094c38e33fb45dc1b0156 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 diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- 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 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 *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 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 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, "");