在我自己的nginx模块中,如何获取全局变量

时间:2014-08-05 06:27:12

标签: nginx module

我想在我自己的模块中获取全局变量,如何获取,或者我可以从其他变量重写remote_add。

例如,我想检查IP信息,我可以在URL中输入IP,然后在浏览器中显示IP信息。

1 个答案:

答案 0 :(得分:0)

我知道如何获取,我们必须从配置文件中获取,像这样,echo $ param。 你可以在这里看到源代码:

elcf = ngx_http_get_module_loc_conf(r, ngx_http_echo_module);
cmds = elcf->handler_cmds;

ngx_int_t
ngx_http_echo_run_cmds(ngx_http_request_t *r)
{
ngx_http_echo_loc_conf_t    *elcf;
ngx_http_echo_ctx_t         *ctx;
ngx_int_t                    rc;
ngx_array_t                 *cmds;
ngx_array_t                 *computed_args = NULL;
ngx_http_echo_cmd_t         *cmd;
ngx_http_echo_cmd_t         *cmd_elts;
ngx_array_t                 *opts = NULL;


elcf = ngx_http_get_module_loc_conf(r, ngx_http_echo_module);
cmds = elcf->handler_cmds;