The location configuration bug?
Denis Erygin
erygin at corp.mail.ru
Tue Oct 9 17:54:42 MSD 2007
Добрый день,
Обнаружил следующие "странности" при обработке конфигурации "location" уровня
в модуле-фильтре:
worker_processes 1;
daemon off;
master_process off;
* * * *
http {
* * *
server {
* * *
location / {
use on;
debug on;
}
location /backend {
proxy_pass ....;
}
}
}
=============================================================
typedef struct {
ngx_flag_t use;
ngx_flag_t debug;
} ngx_http_draft_loc_conf_t;
static ngx_command_t ngx_http_draft_filter_commands[] = {
{ ngx_string("use"),
NGX_HTTP_LOC_CONF | NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_draft_loc_conf_t, enable),
NULL },
{ ngx_string("debug"),
NGX_HTTP_LOC_CONF | NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_draft_loc_conf_t, debug),
NULL },
ngx_null_command
};
static ngx_http_module_t ngx_http_draft_module_ctx = {
NULL, // preconfiguration
ngx_http_draft_filter_init, // postconfiguration
NULL, // create main configuration
NULL, // init main configuration
NULL, // create server configuration
NULL, // merge server configuration
ngx_http_draft_create_loc_conf, // create location configuration
ngx_http_draft_merge_loc_conf // merge location configuration
};
static ngx_int_t ngx_http_draft_filter_init ( ngx_conf_t* cf )
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_draft_header_filter;
ngx_http_next_body_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_draft_body_filter;
return NGX_OK;
}
static void* ngx_http_draft_create_loc_conf ( ngx_conf_t* cf )
{
unsigned i;
ngx_http_draft_loc_conf_t* conf;
conf = ngx_pcalloc ( cf->pool, sizeof(ngx_http_draft_loc_conf_t) );
if ( conf == NULL ) return NGX_CONF_ERROR;
printf("ngx_http_draft_create_loc_conf('%s', %p, %d)\n", cf->name, cf->args, cf->args->nelts);
char** arr = cf->args->elts; // какой формат элементов массива?
for (i = 0; i < cf->args->nelts; i++)
{
printf("[%p]\n", arr[i]);
}
conf->use = NGX_CONF_UNSET;
conf->debug = NGX_CONF_UNSET;
return conf;
}
static char* ngx_http_draft_merge_loc_conf ( ngx_conf_t* cf, void* parent, void* child )
{
unsigned int i;
ngx_http_draft_loc_conf_t* prev = parent;
ngx_http_draft_loc_conf_t* conf = child;
ngx_conf_merge_value ( conf->use, prev->use, 0 );
ngx_conf_merge_value ( conf->debug, prev->debug, 0 );
printf("ngx_http_draft_merge_loc_conf('%s', %p, %d): use: %d, debug: %d\n",
cf->name, cf->args, cf->args->nelts, conf->use, conf->debug);
return NGX_CONF_OK;
}
===========================================================================
$ sbin/nginx -t
ngx_http_draft_create_loc_conf('(null)', 0x80b3878, 1)
[0x4] - какой формат?
ngx_http_draft_create_loc_conf('(null)', 0x80b3878, 1)
[0x6]
ngx_http_draft_create_loc_conf('(null)', 0x80b3878, 2)
[0x8]
[0x80c1b7c]
ngx_http_draft_create_loc_conf('(null)', 0x80b3878, 2)
[0x8]
[0x80c2130]
ngx_http_draft_merge_loc_conf('(null)', 0x80b3878, 0): use: 0, debug: 0
ngx_http_draft_merge_loc_conf('(null)', 0x80b3878, 0): use: 1, debug: 1
ngx_http_draft_merge_loc_conf('(null)', 0x80b3878, 0): use: 0, debug: 0
2007/10/09 17:41:14 [info] 18647#0: the configuration file conf/nginx.conf syntax is ok
2007/10/09 17:41:14 [info] 18647#0: the configuration file conf/nginx.conf was tested successfully
===========================================================================
1) Откуда вызовы до "location / {}" ?
2) Число вызовов "ngx_http_draft_create_loc_conf" и "ngx_http_draft_merge_loc_conf" несовпадает?
3) Последний вызов "ngx_http_draft_merge_loc_conf" (видимо "location /backend {}"?) сбрасывает use и debug.
В результате, если получить указатель
ngx_http_draft_loc_conf_t* conf = ngx_http_get_module_loc_conf ( r, ngx_http_draft_filter_module );
в ngx_http_draft_body_filter( url = "/" ), то получим:
conf->use = conf->debug = 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx-ru/attachments/20071009/00a12969/attachment.html>
More information about the nginx-ru
mailing list