mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
Improved diagnostics when a directive is specified in the wrong context.
This commit is contained in:
parent
7f3a352e5a
commit
1c31039d1e
@ -282,24 +282,16 @@ ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
|
|||||||
{
|
{
|
||||||
char *rv;
|
char *rv;
|
||||||
void *conf, **confp;
|
void *conf, **confp;
|
||||||
ngx_uint_t i, multi;
|
ngx_uint_t i, found;
|
||||||
ngx_str_t *name;
|
ngx_str_t *name;
|
||||||
ngx_command_t *cmd;
|
ngx_command_t *cmd;
|
||||||
|
|
||||||
name = cf->args->elts;
|
name = cf->args->elts;
|
||||||
|
|
||||||
multi = 0;
|
found = 0;
|
||||||
|
|
||||||
for (i = 0; ngx_modules[i]; i++) {
|
for (i = 0; ngx_modules[i]; i++) {
|
||||||
|
|
||||||
/* look up the directive in the appropriate modules */
|
|
||||||
|
|
||||||
if (ngx_modules[i]->type != NGX_CONF_MODULE
|
|
||||||
&& ngx_modules[i]->type != cf->module_type)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = ngx_modules[i]->commands;
|
cmd = ngx_modules[i]->commands;
|
||||||
if (cmd == NULL) {
|
if (cmd == NULL) {
|
||||||
continue;
|
continue;
|
||||||
@ -315,16 +307,18 @@ ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
found = 1;
|
||||||
|
|
||||||
|
if (ngx_modules[i]->type != NGX_CONF_MODULE
|
||||||
|
&& ngx_modules[i]->type != cf->module_type)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* is the directive's location right ? */
|
/* is the directive's location right ? */
|
||||||
|
|
||||||
if (!(cmd->type & cf->cmd_type)) {
|
if (!(cmd->type & cf->cmd_type)) {
|
||||||
if (cmd->type & NGX_CONF_MULTI) {
|
continue;
|
||||||
multi = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
goto not_allowed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
|
if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
|
||||||
@ -408,17 +402,16 @@ ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multi == 0) {
|
if (found) {
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
"unknown directive \"%s\"", name->data);
|
"\"%s\" directive is not allowed here", name->data);
|
||||||
|
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
not_allowed:
|
|
||||||
|
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
"\"%s\" directive is not allowed here", name->data);
|
"unknown directive \"%s\"", name->data);
|
||||||
|
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
|
|
||||||
invalid:
|
invalid:
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
#define NGX_CONF_ANY 0x00000400
|
#define NGX_CONF_ANY 0x00000400
|
||||||
#define NGX_CONF_1MORE 0x00000800
|
#define NGX_CONF_1MORE 0x00000800
|
||||||
#define NGX_CONF_2MORE 0x00001000
|
#define NGX_CONF_2MORE 0x00001000
|
||||||
#define NGX_CONF_MULTI 0x00002000
|
#define NGX_CONF_MULTI 0x00000000 /* compatibility */
|
||||||
|
|
||||||
#define NGX_DIRECT_CONF 0x00010000
|
#define NGX_DIRECT_CONF 0x00010000
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ static ngx_command_t ngx_http_core_commands[] = {
|
|||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("server"),
|
{ ngx_string("server"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
|
NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
||||||
ngx_http_core_server,
|
ngx_http_core_server,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
Loading…
Reference in New Issue
Block a user