Welcome! Log In Create A New Profile

Advanced

ngx_http_get_module_loc_conf возвращает NULL

September 18, 2013 04:04AM
Написал маленький модуль. Но почему-то не могу получить конфигурации локации - возвращается 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;
}
}
}
Subject Author Posted

ngx_http_get_module_loc_conf возвращает NULL

Aleus Essentia September 18, 2013 04:04AM

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

Валентин Бартенев September 18, 2013 09:16AM

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

Aleus Essentia September 18, 2013 06:59PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 206
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready