Nginx-ru mailing list archive (nginx-ru@sysoev.ru)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ngx http get module loc conf возвращает NULL
- To: nginx-ru@xxxxxxxxx
- Subject: ngx http get module loc conf возвращает NULL
- From: "Aleus Essentia" <nginx-forum@xxxxxxxx>
- Date: Wed, 18 Sep 2013 04:04:54 -0400
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=helium.jlkhosting.com; s=x; h=Date:Sender:From:Message-ID:Content-Transfer-Encoding:Content-Type:Subject:To; bh=7GjyXzb8RFI6AjMquDC4Je1N3dlkhcRQ6otWRlE9LkQ=; b=ShOnqfEoqNToIXL5saRk6/dfQJkMRg8O3kGCcTtZT2xQrpTWDTVxudo+5Ksd8D/HJJxSLhRdkZbjw+xBfe0Si5jJSXDJjDNjNDuR2Z6OP1c4L42+mhPsshAF//yYJnLhMXvuNWjxbErnMvTj0apw+Lnch4RS8XZOPJbAi3hlxcE=;
Написал маленький модуль. Но почему-то не могу получить конфигурации локации
- возвращается 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 mailing list
nginx-ru@xxxxxxxxx
http://mailman.nginx.org/mailman/listinfo/nginx-ru
|