<div dir="ltr"><div><div><div>Hello,<br><br></div>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. <br></div>With servers I came out to following solution:<br><br>static ngx_int_t <br>ngx_http_mega_init_process(ngx_cycle_t *cycle)<br>{<br>    ngx_uint_t                   s;<br>    <br>    ngx_http_core_srv_conf_t   **cscfp;<br>    ngx_http_core_main_conf_t   *cmcf;<br>    ngx_http_mega_srv_conf_t    *sscf; /* My module configuration */<br><br>    cmcf  = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);<br>    cscfp = cmcf->servers.elts;<br><br>    for (s = 0; s < cmcf->servers.nelts; s++) {<br><br>        sscf = cscfp[s]->ctx->srv_conf[ngx_http_mega_module.ctx_index];<br><br>        if (!sscf || !sscf->enable) {<br>            continue;<br>        }<br>        <br></div>        <specific initialization functions><br><div>    }<br>}<br><br><br></div><div>But how to iterate over locations in the server?<br></div><div>Is there are any other module, what have similar logic?<br></div><div>Or any other place, where I can find inspiration?<br><br></div><div>I've tried following, but with no luck:<br><br>    ngx_http_core_srv_conf_t   **cscfp;<br>    ngx_http_core_loc_conf_t   **clcfp;<br>    ngx_http_core_srv_conf_t    *cscf;<br><br>    cmcf  = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);<br>    cscfp = cmcf->servers.elts;<br><br>    for (s = 0; s < cmcf->servers.nelts; s++) {<br><br>        cscf = cscfp[s];<br>- OR -<br>        cscf = cscfp[s]->ctx->srv_conf[ngx_http_core_module.ctx_index];<br><br>        if (cscf->named_locations) {<br><br>            for (clcfp = cscf->named_locations; *clcfp; clcfp++) {<br><br>                ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cycle->log, 0,<br>                               "MEGA test location: \"%V\"", &(*clcfp)->name);<br>            }<br>        }<br><br>here cscf->named_locations is always NULL in both cases, despite I have a lot of locations in my servers configured in nginx.conf.<br><br><br>--<br></div><div>Best wishes,<br></div><div>Andrey Kulikov<br></div></div>