日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx http子模块conf的初始化

發布時間:2023/12/19 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的初始化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。