[nginx源码分析]配置解析(location作用域)

Location命令所在模块为ngx_http_core_module

     { ngx_string("location"),
	 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
        ngx_http_core_location,                                                                                                                                                                                                          
        NGX_HTTP_SRV_CONF_OFFSET,
        0,
        NULL },

回调函数首先创建ngx_http_conf_ctx_t上下文,然后

ctx->main_conf = srv->ctx->main_conf
ctx->srv_conf = srv->crx->srv_conf;
ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void*)* ngx_http_max_module)

后面调用每一个NGX_HTTP_MODULE的create_loc_conf方法来把创建出来的结构根据模块的ctx_index保存到相应ctx->loc_conf下面

     clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
     clcf->loc_conf = ctx->loc_conf;

上面获取ngx_http_core_module的loc的结构,同时把当前location的ctx保存在clcf->loc_conf下面的代码就是构造当前上下文。

pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
     if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {                                                                                                                                                                
         return NGX_CONF_ERROR;
     }

把当先上下文保存在父loc_ctx的locaitons下面

然后又间接递归调用ngx_conf_parse进行解析

Root就不写了

下面就开始写index

Index是属于ngx_http_index_module的

 static ngx_command_t  ngx_http_index_commands[] = { 
      { ngx_string("index"),       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
        ngx_http_index_set_index,
        NGX_HTTP_LOC_CONF_OFFSET,
        0,
        NULL },
  
        ngx_null_command
  };

保存在index模块下面了loc上下文中





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值