mirror of
https://github.com/nginx/nginx.git
synced 2025-08-06 06:46:16 +08:00
move setting conf->server_name in merge phase
This commit is contained in:
parent
cc878dc6ac
commit
cfc5c25589
@ -2990,6 +2990,7 @@ 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 *prev = parent;
|
||||||
ngx_http_core_srv_conf_t *conf = child;
|
ngx_http_core_srv_conf_t *conf = child;
|
||||||
|
|
||||||
|
ngx_str_t name;
|
||||||
ngx_http_server_name_t *sn;
|
ngx_http_server_name_t *sn;
|
||||||
|
|
||||||
/* TODO: it does not merge, it inits only */
|
/* TODO: it does not merge, it inits only */
|
||||||
@ -3021,14 +3022,9 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
ngx_conf_merge_value(conf->underscores_in_headers,
|
ngx_conf_merge_value(conf->underscores_in_headers,
|
||||||
prev->underscores_in_headers, 0);
|
prev->underscores_in_headers, 0);
|
||||||
|
|
||||||
if (conf->server_name.data == NULL) {
|
if (conf->server_names.nelts == 0) {
|
||||||
ngx_str_set(&conf->server_name, "");
|
/* the array has 4 empty preallocated elements, so push can not fail */
|
||||||
|
|
||||||
sn = ngx_array_push(&conf->server_names);
|
sn = ngx_array_push(&conf->server_names);
|
||||||
if (sn == NULL) {
|
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (NGX_PCRE)
|
#if (NGX_PCRE)
|
||||||
sn->regex = NULL;
|
sn->regex = NULL;
|
||||||
#endif
|
#endif
|
||||||
@ -3036,6 +3032,27 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
ngx_str_set(&sn->name, "");
|
ngx_str_set(&sn->name, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sn = conf->server_names.elts;
|
||||||
|
name = sn[0].name;
|
||||||
|
|
||||||
|
#if (NGX_PCRE)
|
||||||
|
if (sn->regex) {
|
||||||
|
name.len++;
|
||||||
|
name.data--;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (name.data[0] == '.') {
|
||||||
|
name.len--;
|
||||||
|
name.data++;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->server_name.len = name.len;
|
||||||
|
conf->server_name.data = ngx_pstrdup(cf->pool, &name);
|
||||||
|
if (conf->server_name.data == NULL) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3625,29 +3642,12 @@ ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
ngx_http_core_srv_conf_t *cscf = conf;
|
ngx_http_core_srv_conf_t *cscf = conf;
|
||||||
|
|
||||||
u_char ch;
|
u_char ch;
|
||||||
ngx_str_t *value, name;
|
ngx_str_t *value;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_http_server_name_t *sn;
|
ngx_http_server_name_t *sn;
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
ch = value[1].data[0];
|
|
||||||
|
|
||||||
if (cscf->server_name.data == NULL) {
|
|
||||||
name = value[1];
|
|
||||||
|
|
||||||
if (ch == '.') {
|
|
||||||
name.len--;
|
|
||||||
name.data++;
|
|
||||||
}
|
|
||||||
|
|
||||||
cscf->server_name.len = name.len;
|
|
||||||
cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
|
|
||||||
if (cscf->server_name.data == NULL) {
|
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < cf->args->nelts; i++) {
|
for (i = 1; i < cf->args->nelts; i++) {
|
||||||
|
|
||||||
ch = value[i].data[0];
|
ch = value[i].data[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user