nginx配置文件解析

Nginx为微内核加可扩展模块。自身模块有core、event、http、mail等核心模块。开发者可以基于这些核心模块开发满足自身业务需求的模块,主要是http模块。

nginx的配置项的数据结构:


struct ngx_cycle_s {
    void    ****conf_ctx;
    ......
}
conf_ctx是一个指针数组,数组一共有ngx_max_module项(nginx有多少个模块数组就有多大),每一项是void*。void*数组里的每一项指向的是每个模块的create_conf()方法的结果。如core模块的ngx_core_module_create_conf(),但对于大部分模块来说,并没有实现该方法,如http_core模块对应的该项为NULL。

当遇到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);

四重指针

  每一项指向一个数组指针如图一。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值