How to obtain location field in my module

Maxim Dounin mdounin at mdounin.ru
Fri Dec 13 10:45:25 UTC 2013


Hello!

On Fri, Dec 13, 2013 at 11:06:47AM +0400, Deymon wrote:

> 
> Hi friends!
> I have a question: How can I obtain the location path in http-handler which
> handles requests intended to this location?
> Here is what I mean:
> 
> http {
>   ...
> 
>   server {
>     ...
> 
>     location <location_path> { # I need
> <location_path> value
>         ...
>     }
> 
>     ...
>   }
> 
>   ...
> }
> 
>  Thanks for attention!

The is "name" in ngx_http_core_module location config, but note 
that it's not always a path - there are named and/or regexp 
locations.

E.g., the proxy module does this during configuration merge to 
later use the location path in internal operations:

    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);

    ...

    plcf->location = clcf->name;

    if (clcf->named
#if (NGX_PCRE)
        || clcf->regex
#endif
        || clcf->noname)
    {
        if (plcf->vars.uri.len) {
            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                               "\"proxy_pass\" cannot have URI part in "
                               "location given by regular expression, "
                               "or inside named location, "
                               "or inside \"if\" statement, "
                               "or inside \"limit_except\" block");
            return NGX_CONF_ERROR;
        }

        plcf->location.len = 0;
    }

See http/modules/ngx_http_proxy_module.c for all the code.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list