NGINX 模块退出线程/主回调
我的小 nginx 模块遇到了一些麻烦(和头痛)。 我最近看到了很多模块代码,以及大量有关 nginx 模块的内容,但我无法做到我需要做的事情。 这是我的问题: 我创建了自己的 nginx 模块,名为“mymodule”。它的 loc_conf 结构如下所示:
typedef struct {
void *serverConf;
ngx_str_t server_file;
} ngx_http_mymodule_loc_conf_t;
它的命令结构如下所示:
static ngx_command_t ngx_http_mymodule_commands[] = {
{
ngx_string("mymodule"),
NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1,
ngx_http_mymodule,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL
},
ngx_null_command
};
在 ngx_http_mymodule 函数中,我做了一些事情并在 ngx_http_mymodule_loc_conf_t 中设置了 serverConf 指针。 问题是我想在线程/进程退出时检索该 serverConf 指针。但是退出线程进程或 master 时给予 ngx_module_t 的唯一参数是 ngx_cycle_t* ,我找不到如何从中检索 ngx_http_mymodule_loc_conf_t 以便处理该 serverConf 指针。
[编辑] 我已经在线程退出回调中尝试过此操作,但没有成功获得非空的 serverConf 指针:
ngx_http_mymodule_loc_conf_t *mymodulecf = (ngx_http_mymodule_loc_conf_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_mymodule_module);
任何帮助或想法将不胜感激:) 提前致谢。
I'm experiencing some troubles (and headaches) with my little nginx module.
I've seen a lot of module code lately, and a ton of stuff about nginx modules but I can't manage to do what I need to.
Here is my problem:
I have created my own nginx module called "mymodule". Its loc_conf structure looks like that:
typedef struct {
void *serverConf;
ngx_str_t server_file;
} ngx_http_mymodule_loc_conf_t;
its command structure looks like that:
static ngx_command_t ngx_http_mymodule_commands[] = {
{
ngx_string("mymodule"),
NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1,
ngx_http_mymodule,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL
},
ngx_null_command
};
in the ngx_http_mymodule function I do some stuff and set the serverConf pointer in the ngx_http_mymodule_loc_conf_t.
The problem is that I would like to retrieve that serverConf pointer when the thread / process is exited. But the only parameter given to ngx_module_t while exiting thread process or master is a ngx_cycle_t* and I can't find how to retrieve the ngx_http_mymodule_loc_conf_t from it in order to work on that serverConf pointer.
[EDIT]
I have tried this in the thread exit callback with no luck at having a not null serverConf pointer:
ngx_http_mymodule_loc_conf_t *mymodulecf = (ngx_http_mymodule_loc_conf_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_mymodule_module);
Any help or idea would be appreciated :) Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论