nginxnginx-module

in my own nginx's module,how to get the global variable


I want to get global variable in my own module,how to get,or I can rewrite the remote_add from other variable.

for example,I want to check the IP information,and I could input the IP in URL then show the IP information in the brower.


Solution

  • I know how to get,we must get from config file,like this,echo $param. you can see the source code in here :

    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;