ngx http get module loc conf возвращает NULL

Aleus Essentia nginx-forum at nginx.us
Wed Sep 18 08:04:54 UTC 2013


Написал маленький модуль. Но почему-то не могу получить конфигурации локации
- возвращается NULL? Хендлер, в котором нужна конфа находится в фазе
NGX_HTTP_CONTENT_PHASE.
Вот код модуля:

typedef struct {
	ngx_str_t  path;
} ngx_http_ispmngr_loc_conf_t;

static ngx_command_t  ngx_http_mymodule_commands[] = {
    { ngx_string("mymodule"),
      NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
      ngx_http_mymodule,
      NGX_HTTP_LOC_CONF_OFFSET,
      0,
      NULL },

    { ngx_string("path_in_mymodule"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_conf_set_str_slot, 
      NGX_HTTP_LOC_CONF_OFFSET,
      offsetof(ngx_http_mymodule_loc_conf_t, path),
      NULL },

      ngx_null_command
};

static ngx_http_module_t  ngx_http_mymodule_module_ctx = {
    NULL,       
    NULL,       

    NULL,       
    NULL,       

    NULL,       
    NULL,       

    ngx_http_mymodule_create_loc_conf,
    ngx_http_mymodule_merge_loc_conf 
};

ngx_module_t  ngx_http_mymodule_module = {
    NGX_MODULE_V1,
    &ngx_http_mymodule_module_ctx, 
    ngx_http_mymodule_commands,   
    NGX_HTTP_MODULE,              
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    NGX_MODULE_V1_PADDING
};

static ngx_int_t
ngx_http_mymodule_handler (ngx_http_request_t *r)
{
    ngx_http_mymodule_loc_conf_t *clcf
    	= ngx_http_get_module_loc_conf( r, ngx_http_mymodule_module );

	if( clcf ){
		ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "couldn't retrieve
module configurationr.");
		return NGX_ERROR;
	}
   
   // .....
   // some code
   // ....


    return ngx_http_output_filter(r, &out);
}

static char *
ngx_http_mymodule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_core_loc_conf_t    *clcf;

    clcf          = ngx_http_conf_get_module_loc_conf(cf,
ngx_http_core_module);
    clcf->handler = ngx_http_mymodule_handler;

    return NGX_CONF_OK;
}

static void *
ngx_http_mymodule_create_loc_conf(ngx_conf_t *cf)
{
    ngx_http_mymodule_loc_conf_t  *conf;

    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_mymodule_loc_conf_t));
    if (conf == NULL) {
        return NGX_CONF_ERROR;
    }

    return conf;
}

static char *
ngx_http_mymodule_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
    ngx_http_mymodule_loc_conf_t *prev = parent;
    ngx_http_mymodule_loc_conf_t *conf = child;
    ngx_conf_merge_str_value( conf->path, prev->path, "./" );
    return NGX_CONF_OK;
}

Конфигурация NGINX:
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  15;

    server {
        listen       80 default_server;
        listen       3000;
        server_name  localhost expt expt.ru;

        access_log /home/aleus/server/expt/logs.txt;
        error_log  /home/aleus/server/expt/error.txt debug_http;
        charset utf-8;

        location / {
            root  /home/usr/html;
	    path  /home/usr/path;
	    mymodule;
            index  index.html index.htm;
        }
    }
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?21,242940,242940#msg-242940



Подробная информация о списке рассылки nginx-ru