ngx_command_t中定义了配置项的名称、类型、解析方式、存放地址
配置项解析
预设14种(函数)
自定义
配置项合并
预设10种(宏)
自定义
ngx_*_conf_t 存放结构?
配置解析源码分析过程:
- ngx_init_cycle
- ngx_conf_parse
- ngx_conf_handler
- cmd->set()回调函数
- ngx_http_block // http{}
- 关于配置项http{}、server{}、location{}的存储,还需看视频进行理解
好复杂!!!
分配指针内存空间
cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));
if (cycle->conf_ctx == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
各自调用create_conf钩子函数,分配模块对应配置结构空间
for (i = 0; cycle->modules[i]; i++) {
if (cycle->modules[i]->type != NGX_CORE_MODULE) {
continue;
}
module = cycle->modules[i]->ctx;
if (module->create_conf) {
rv = module->create_conf(cycle); // 参考 ngx_core_module_create_conf
if (rv == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
cycle->conf_ctx[cycle->modules[i]->index] = rv;
}
}