nginx http ctx

模块上下文

一般情况下我们会对自己的模块设置、获取上下文通过调用接口:

#define ngx_http_get_module_ctx(r, module)  (r)->ctx[module.ctx_index]
#define ngx_http_set_ctx(r, c, module)      r->ctx[module.ctx_index] = c;

其中 module 参数是模块变量。

不同阶段间上下文传递

如果要在不同阶段间传递参数,可以将模块变量声明为 extern 然后在本模块就可以使用。