Nginx为微内核加可扩展模块。自身模块有core、event、http、mail等核心模块。开发者可以基于这些核心模块开发满足自身业务需求的模块,主要是http模块。
nginx的配置项的数据结构:
struct ngx_cycle_s {
void ****conf_ctx;
......
}
当遇到http指令时,会调用该指令的解析函数ngx_http_block。
函数中有ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); *(ngx_http_conf_ctx_t **) conf = ctx;
首先为http模块分配一个ngx_http_conf_ctx_t结构,把该结构存储在conf指针指向的内存处,conf指针来源是ngx_conf_handler()。conf代表cycle->conf_ctx[ngx_http_core_module]的指针,*(ngx_http_conf_ctx_t **) conf = ctx; 就是将ctx(指向ngx_http_conf_ctx结构的指针)放在数组的这一项里面。
初始化该ngx_http_conf_ctx_t结构。
ctx->main_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
四重指针
每一项指向一个数组指针如图一。