nginx http子模块conf的初始化
nginx.conf文件中有http這個模塊,里邊可以加入各種子模塊ngx_http_module_t ,這些子模塊自定義conf的初始化過程如下??
?
一、幾個結構
?
ngx_conf_t????????????????? // 路人甲
ngx_http_XXX_(main|srv|loc)_conf_t???? // 自定義的conf結構
ngx_command_t??????? // 各個Directives
ngx_http_module_t???// http中的子module
ngx_module_t???????????// 高層module
?
二、一些函數
http中子module初始化的過程:
main -> ngx_init_cycle -> ngx_conf_param -> ngx_conf_param -> ngx_conf_handler -> ngx_http_block -> ngx_http_merge_servers
在最后兩個函數中調用了ngx_http_module_t結構中各個create、init和merge函數做自定義conf結構的初始化、合并等。
?
?
?
?
1. Main中調用了ngx_init_cycle,做了以下操作:
//?ngx_module_t??ngx_http_module是NGX_CORE_MODULE
?
rv?=?module->create_conf(cycle);
cycle->conf_ctx[ngx_modules[i]->index]?=?rv;
?
conf.ctx?=?cycle->conf_ctx;.?//此外的conf是一個ngx_conf_t
?
?
2. Ngx_init_cycle調用了ngx_conf_param,把上邊conf傳過來
ngx_conf_param(&conf)
?
?
3. Nginx_conf_param調用ngx_conf_parse
?rv?=?ngx_conf_parse(cf,?NULL);,又接收了上方
?
?
4. ngx_conf_parse調用ngx_conf_handler
rc?=?ngx_conf_handler(cf,?rc);,又接收上方
?
?
5. Ngx_conf_handler中把conf取出并傳給module中各命令的set函數。
conf?=?NULL;
if?(cmd->type?&?NGX_DIRECT_CONF)?{
????conf?=?((void?**)?cf->ctx)[ngx_modules[i]->index];
}?else?if?(cmd->type?&?NGX_MAIN_CONF)?{
????conf?=?&(((void?**)?cf->ctx)[ngx_modules[i]->index]);
}?else?if?(cf->ctx)?{
????confp?=?*(void?**)?((char?*)?cf->ctx?+?cmd->conf);
????if?(confp)?{
????????conf?=?confp[ngx_modules[i]->ctx_index];
????}
}
rv?=?cmd->set(cf,?cmd,?conf);?
?
?
6. Ngx_http_module_t中的http命令的set函數為ngx_http_block,其中做了一系列的各模塊自定義的conf的創建、初始化等操作。最后調用的ngx_http_merge_servers又調用了各個merge函數。
for?(m?=?0;?ngx_modules[m];?m++)?{
?
????????ctx->main_conf[mi]?=?module->create_main_conf(cf);
????????ctx->srv_conf[mi]?=?module->create_srv_conf(cf);
????????ctx->loc_conf[mi]?=?module->create_loc_conf(cf);
}????
?
for?(m?=?0;?ngx_modules[m];?m++)?{
?
???????module->preconfiguration(cf)
}
for?(m?=?0;?ngx_modules[m];?m++)?{
?
????????rv?=?module->init_main_conf(cf,?ctx->main_conf[mi]);
????rv?=?ngx_http_merge_servers(cf,?cmcf,?module,?mi);?//?此處調用了各merge
}
for?(m?=?0;?ngx_modules[m];?m++)?{
????module->postconfiguration(cf)
}
?
?
?
7. ngx_http_merge_servers又調用了各個merge函數。
for?(s?=?0;?s?<?cmcf->servers.nelts;?s++)?{
????????rv?=?module->merge_srv_conf(cf,?saved.srv_conf[ctx_index],
????????????????????????????????????cscfp[s]->ctx->srv_conf[ctx_index]);
????????rv?=?module->merge_loc_conf(cf,?saved.loc_conf[ctx_index],
????????????????????????????????????cscfp[s]->ctx->loc_conf[ctx_index]);
}
?
?
?
轉載于:https://www.cnblogs.com/sunyongyue/archive/2011/09/05/ngx_http_module_conf_init.html
總結
以上是生活随笔為你收集整理的nginx http子模块conf的初始化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows 卸载IE8还原IE7的方
- 下一篇: 应用程序环境块相关代码