Welcome! Log In Create A New Profile

Advanced

[Q] How to iterate over configured locations on process init in custom module?

Andrey Kulikov
October 06, 2016 05:42AM
Hello,

I wrote a custom nginx module, which require specific initialization in
worker process (it can't be done in master process). Initialization should
be performed if server OR location meet certain criteria.
With servers I came out to following solution:

static ngx_int_t
ngx_http_mega_init_process(ngx_cycle_t *cycle)
{
ngx_uint_t s;

ngx_http_core_srv_conf_t **cscfp;
ngx_http_core_main_conf_t *cmcf;
ngx_http_mega_srv_conf_t *sscf; /* My module configuration */

cmcf = ngx_http_cycle_get_module_main_conf(cycle,
ngx_http_core_module);
cscfp = cmcf->servers.elts;

for (s = 0; s < cmcf->servers.nelts; s++) {

sscf = cscfp[s]->ctx->srv_conf[ngx_http_mega_module.ctx_index];

if (!sscf || !sscf->enable) {
continue;
}

<specific initialization functions>
}
}


But how to iterate over locations in the server?
Is there are any other module, what have similar logic?
Or any other place, where I can find inspiration?

I've tried following, but with no luck:

ngx_http_core_srv_conf_t **cscfp;
ngx_http_core_loc_conf_t **clcfp;
ngx_http_core_srv_conf_t *cscf;

cmcf = ngx_http_cycle_get_module_main_conf(cycle,
ngx_http_core_module);
cscfp = cmcf->servers.elts;

for (s = 0; s < cmcf->servers.nelts; s++) {

cscf = cscfp[s];
- OR -
cscf = cscfp[s]->ctx->srv_conf[ngx_http_core_module.ctx_index];

if (cscf->named_locations) {

for (clcfp = cscf->named_locations; *clcfp; clcfp++) {

ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cycle->log, 0,
"MEGA test location: \"%V\"",
&(*clcfp)->name);
}
}

here cscf->named_locations is always NULL in both cases, despite I have a
lot of locations in my servers configured in nginx.conf.


--
Best wishes,
Andrey Kulikov
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[Q] How to iterate over configured locations on process init in custom module?

Andrey Kulikov 370 October 06, 2016 05:42AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 145
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready