ngx_command_t中定义了配置项的名称、类型、解析方式、存放地址
    配置项解析
    预设14种(函数)
    自定义
    配置项合并
    预设10种(宏)
    自定义

    ngx_*_conf_t 存放结构?

    配置解析源码分析过程:

    1. ngx_init_cycle
    2. ngx_conf_parse
    3. ngx_conf_handler
    4. cmd->set()回调函数
      1. ngx_http_block // http{}
    • 关于配置项http{}、server{}、location{}的存储,还需看视频进行理解

    好复杂!!!

    1. 分配指针内存空间

      1. cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));
      2. if (cycle->conf_ctx == NULL) {
      3. ngx_destroy_pool(pool);
      4. return NULL;
      5. }
    2. 各自调用create_conf钩子函数,分配模块对应配置结构空间

      1. for (i = 0; cycle->modules[i]; i++) {
      2. if (cycle->modules[i]->type != NGX_CORE_MODULE) {
      3. continue;
      4. }
      5. module = cycle->modules[i]->ctx;
      6. if (module->create_conf) {
      7. rv = module->create_conf(cycle); // 参考 ngx_core_module_create_conf
      8. if (rv == NULL) {
      9. ngx_destroy_pool(pool);
      10. return NULL;
      11. }
      12. cycle->conf_ctx[cycle->modules[i]->index] = rv;
      13. }
      14. }

      Nginx 配置详解 | 菜鸟教程