mirror of
https://github.com/nginx/nginx.git
synced 2024-12-23 15:40:03 -06:00
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
This commit is contained in:
parent
21dba41f5b
commit
7087d5d72a
@ -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, "");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user