1

我的小 nginx 模块遇到了一些麻烦(和头痛)。我最近看到了很多模块代码,还有很多关于 nginx 模块的东西,但我无法做我需要做的事情。这是我的问题:我创建了自己的名为“mymodule”的 nginx 模块。它的 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 指针。但是在退出线程进程或主进程时给 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);

任何帮助或想法将不胜感激:) 在此先感谢。

4

0 回答 0