Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65156
  • 博文数量: 15
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-04 17:12
个人简介

It

文章分类

全部博文(15)

文章存档

2015年(13)

2014年(2)

我的朋友

分类: LINUX

2015-07-06 12:43:32

1. nginx配置说明

nginx的配置文件在nginx系统中占有非常重要地位。
nginx的配置文件,它具有层次性。可以树来表示nginx的配置文件,假想一个树根ROOT,配置文件中配置命令 daemon、event、http等,是ROOT的孩子,而event、http又有自己的孩子。如下图:

 



2. nginx配置文件解析

nginx对配置的解析处理就是对该配置树进行递归的深度优先遍历出各个配置命令,然后对每个配置指令进行处理。

现在看一下nginx源码是如何解析配置文件的。

--main
 --ngx_init_cycle
   --ngx_conf_parse

2.1 ngx_cycle_init

nginx对配置文件的解析,对复杂的应该是http部分的解析处理。http部分的配置解析是当遇到'http'配置命令开始的,从上面的配置树中,我知道http部分的配置指令又分为多个层次
http server location等。

点击(此处)折叠或打开

  1. ngx_cycle_t *
  2. ngx_init_cycle(ngx_cycle_t *old_cycle)
  3. {
  4.     // ......
  5.     ngx_conf_t conf;
  6.     
  7.     // ......
  8.     
  9.     // 设置配置上下文
  10.     conf.ctx = cycle->conf_ctx;
  11.     conf.cycle = cycle;
  12.     conf.pool = pool;
  13.     conf.log = log;
  14.     conf.module_type = NGX_CORE_MODULE; //
  15.     conf.cmd_type = NGX_MAIN_CONF;

  16. #if 0
  17.     log->log_level = NGX_LOG_DEBUG_ALL;
  18. #endif

  19.     if (ngx_conf_param(&conf) != NGX_CONF_OK) {
  20.         environ = senv;
  21.         ngx_destroy_cycle_pools(&conf);
  22.         return NULL;
  23.     }

  24.     if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {
  25.         environ = senv;
  26.         ngx_destroy_cycle_pools(&conf);
  27.         return NULL;
  28.     }
  29.     // 至此,配置文件已经解析完毕
  30.     
  31.     // ......
  32. }
'http'配置指令属于 ngx_http_module 核心模块。该核心模块作为http部分的代理,是nginx系统处理http部分的入口。

点击(此处)折叠或打开

  1. static ngx_command_t ngx_http_commands[] = {

  2.     { ngx_string("http"),
  3.       NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
  4.       ngx_http_block,
  5.       0,
  6.       0,
  7.       NULL },

  8.       ngx_null_command
  9. };


  10. static ngx_core_module_t ngx_http_module_ctx = {
  11.     ngx_string("http"),
  12.     NULL,
  13.     NULL
  14. };


  15. ngx_module_t ngx_http_module = {
  16.     NGX_MODULE_V1,
  17.     &ngx_http_module_ctx, /* module context */
  18.     ngx_http_commands, /* module directives */
  19.     NGX_CORE_MODULE, /* module type */
  20.     NULL, /* init master */
  21.     NULL, /* init module */
  22.     NULL, /* init process */
  23.     NULL, /* init thread */
  24.     NULL, /* exit thread */
  25.     NULL, /* exit process */
  26.     NULL, /* exit master */
  27.     NGX_MODULE_V1_PADDING
  28. };

2.2 ngx_http_block
当遇到'http'配置命令是,nginx的调用 ngx_http_block()进行处理:

点击(此处)折叠或打开

  1. static char *
  2. ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  3. {
  4.     char *rv;
  5.     ngx_uint_t mi, m, s;
  6.     ngx_conf_t pcf;
  7.     ngx_http_module_t *module;
  8.     ngx_http_conf_ctx_t *ctx;
  9.     ngx_http_core_loc_conf_t *clcf;
  10.     ngx_http_core_srv_conf_t **cscfp;
  11.     ngx_http_core_main_conf_t *cmcf;

  12.     /* the main http context */
  13.     /*
  14.      * typedef struct {
  15.      * void **main_conf;
  16.      * void **srv_conf;
  17.      * void **loc_conf;
  18.      * } ngx_http_conf_ctx_t;
  19.      * ctx == ngx_http_conf_ctx_t
  20.      * main_conf -> [ m0 ] [ m1 ] ... [ ngx_http_max_module - 1]
  21.      * srv_conf -> [ s0 ] [ s1 ] ... [ ngx_http_max_module - 1]
  22.      * loc_conf -> [ l0 ] [ l1 ] ... [ ngx_http_max_module - 1]
  23.      */
  24.     ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
  25.     if (ctx == NULL) {
  26.         return NGX_CONF_ERROR;
  27.     }

  28.     // 保存到 cycle->conf_ctx[ngx_http_module.index]
  29.     *(ngx_http_conf_ctx_t **) conf = ctx;


  30.     /* count the number of the http modules and set up their indices */

  31.     ngx_http_max_module = 0;
  32.     for (m = 0; ngx_modules[m]; m++) {
  33.         if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
  34.             continue;
  35.         }

  36.         ngx_modules[m]->ctx_index = ngx_http_max_module++;
  37.     }


  38.     /* the http main_conf context, it is the same in the all http contexts */
  39.     // main_conf -> [ m0 ] [ m1 ] ... [ ngx_http_max_module - 1]

  40.     ctx->main_conf = ngx_pcalloc(cf->pool,
  41.                                  sizeof(void *) * ngx_http_max_module);
  42.     if (ctx->main_conf == NULL) {
  43.         return NGX_CONF_ERROR;
  44.     }


  45.     /*
  46.      * the http null srv_conf context, it is used to merge
  47.      * the server{}s' srv_conf's
  48.      */
  49.     // srv_conf -> [ s0 ] [ s1 ] ... [ ngx_http_max_module - 1]

  50.     ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
  51.     if (ctx->srv_conf == NULL) {
  52.         return NGX_CONF_ERROR;
  53.     }


  54.     /*
  55.      * the http null loc_conf context, it is used to merge
  56.      * the server{}s' loc_conf's
  57.      */
  58.     // loc_conf -> [ l0 ] [ l1 ] ... [ ngx_http_max_module - 1]
  59.     ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
  60.     if (ctx->loc_conf == NULL) {
  61.         return NGX_CONF_ERROR;
  62.     }
  63.     


  64.     /*
  65.      * create the main_conf's, the null srv_conf's, and the null loc_conf's
  66.      * of the all http modules
  67.      */
  68.     //
  69.     for (m = 0; ngx_modules[m]; m++) {
  70.         if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
  71.             continue;
  72.         }

  73.         module = ngx_modules[m]->ctx;
  74.         mi = ngx_modules[m]->ctx_index;

  75.         if (module->create_main_conf) {
  76.             ctx->main_conf[mi] = module->create_main_conf(cf);
  77.             if (ctx->main_conf[mi] == NULL) {
  78.                 return NGX_CONF_ERROR;
  79.             }
  80.         }

  81.         if (module->create_srv_conf) {
  82.             ctx->srv_conf[mi] = module->create_srv_conf(cf);
  83.             if (ctx->srv_conf[mi] == NULL) {
  84.                 return NGX_CONF_ERROR;
  85.             }
  86.         }

  87.         if (module->create_loc_conf) {
  88.             ctx->loc_conf[mi] = module->create_loc_conf(cf);
  89.             if (ctx->loc_conf[mi] == NULL) {
  90.                 return NGX_CONF_ERROR;
  91.             }
  92.         }
  93.     }

  94.     // 保存父配置的上下文
  95.     pcf = *cf;
  96.     // 修改为当前配置的上下文
  97.     cf->ctx = ctx;

  98.     for (m = 0; ngx_modules[m]; m++) {
  99.         if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
  100.             continue;
  101.         }

  102.         module = ngx_modules[m]->ctx;

  103.         if (module->preconfiguration) {
  104.             if (module->preconfiguration(cf) != NGX_OK) {
  105.                 return NGX_CONF_ERROR;
  106.             }
  107.         }
  108.     }

  109.     /* parse inside the http{} block */

  110.     
  111.     cf->module_type = NGX_HTTP_MODULE;
  112.     cf->cmd_type = NGX_HTTP_MAIN_CONF;
  113.     // 递归解析 'http' 子树部分的配置命令
  114.     rv = ngx_conf_parse(cf, NULL);
  115.     
  116.     // 至此, 'http'子树的配置命令解析完毕
  117.     
  118.     // ......
  119. }

2.3 ngx_http_core_server
当 ngx_http_block 中调用 ngx_conf_parse(), 如果遇到 'server' 配置指令,则会调用 ngx_http_core_server.

点击(此处)折叠或打开

  1. static char *
  2. ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
  3. {
  4.     char *rv;
  5.     void *mconf;
  6.     ngx_uint_t i;
  7.     ngx_conf_t pcf;
  8.     ngx_http_module_t *module;
  9.     struct sockaddr_in *sin;
  10.     ngx_http_conf_ctx_t *ctx, *http_ctx;
  11.     ngx_http_listen_opt_t lsopt;
  12.     ngx_http_core_srv_conf_t *cscf, **cscfp;
  13.     ngx_http_core_main_conf_t *cmcf;

  14.     ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
  15.     if (ctx == NULL) {
  16.         return NGX_CONF_ERROR;
  17.     }

  18.     
  19.     http_ctx = cf->ctx;
  20.     ctx->main_conf = http_ctx->main_conf;

  21.     /* the server{}'s srv_conf */

  22.     ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
  23.     if (ctx->srv_conf == NULL) {
  24.         return NGX_CONF_ERROR;
  25.     }

  26.     /* the server{}'s loc_conf */

  27.     ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
  28.     if (ctx->loc_conf == NULL) {
  29.         return NGX_CONF_ERROR;
  30.     }

  31.     for (i = 0; ngx_modules[i]; i++) {
  32.         if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
  33.             continue;
  34.         }

  35.         module = ngx_modules[i]->ctx;

  36.         if (module->create_srv_conf) {
  37.             mconf = module->create_srv_conf(cf);
  38.             if (mconf == NULL) {
  39.                 return NGX_CONF_ERROR;
  40.             }

  41.             ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
  42.         }

  43.         if (module->create_loc_conf) {
  44.             mconf = module->create_loc_conf(cf);
  45.             if (mconf == NULL) {
  46.                 return NGX_CONF_ERROR;
  47.             }

  48.             ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
  49.         }
  50.     }


  51.     cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
  52.     cscf->ctx = ctx;


  53.     cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];

  54.     cscfp = ngx_array_push(&cmcf->servers);
  55.     if (cscfp == NULL) {
  56.         return NGX_CONF_ERROR;
  57.     }
  58.     *cscfp = cscf;


  59.     pcf = *cf;
  60.     cf->ctx = ctx;
  61.     cf->cmd_type = NGX_HTTP_SRV_CONF;

  62.     // 递归调用 ngx_conf_parse ,解析 'server' 配置块(或者配置子树)中的命令
  63.     rv = ngx_conf_parse(cf, NULL);
  64.     // 至此,该'server'块下的配置命令解析完毕

  65.     // 回复为父亲的配置上下文
  66.     *cf = pcf;

  67.     if (rv == NGX_CONF_OK && !cscf->listen) {
  68.         // 如果该server配置块未配置为listen,则使用默认的端口 80/8000
  69.         ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));

  70.         sin = &lsopt.u.sockaddr_in;

  71.         sin->sin_family = AF_INET;
  72. #if (NGX_WIN32)
  73.         sin->sin_port = htons(80);
  74. #else
  75.         sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
  76. #endif
  77.         sin->sin_addr.s_addr = INADDR_ANY;

  78.         lsopt.socklen = sizeof(struct sockaddr_in);

  79.         lsopt.backlog = NGX_LISTEN_BACKLOG;
  80.         lsopt.rcvbuf = -1;
  81.         lsopt.sndbuf = -1;
  82. #if (NGX_HAVE_SETFIB)
  83.         lsopt.setfib = -1;
  84. #endif
  85.         lsopt.wildcard = 1;

  86.         (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.socklen, lsopt.addr,
  87.                              NGX_SOCKADDR_STRLEN, 1);

  88.         if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) {
  89.             return NGX_CONF_ERROR;
  90.         }
  91.     }

  92.     return rv;
  93. }

2.4  ngx_http_core_location
当 ngx_http_core_server 中调用 ngx_conf_parse(), 如果遇到 'location' 配置指令,则会调用 ngx_http_core_location .

点击(此处)折叠或打开

  1. static char *
  2. ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
  3. {
  4.     char *rv;
  5.     u_char *mod;
  6.     size_t len;
  7.     ngx_str_t *value, *name;
  8.     ngx_uint_t i;
  9.     ngx_conf_t save;
  10.     ngx_http_module_t *module;
  11.     ngx_http_conf_ctx_t *ctx, *pctx;
  12.     ngx_http_core_loc_conf_t *clcf, *pclcf;

  13.     ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
  14.     if (ctx == NULL) {
  15.         return NGX_CONF_ERROR;
  16.     }

  17.     pctx = cf->ctx;
  18.     ctx->main_conf = pctx->main_conf;
  19.     ctx->srv_conf = pctx->srv_conf;

  20.     ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
  21.     if (ctx->loc_conf == NULL) {
  22.         return NGX_CONF_ERROR;
  23.     }

  24.     for (i = 0; ngx_modules[i]; i++) {
  25.         if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
  26.             continue;
  27.         }

  28.         module = ngx_modules[i]->ctx;

  29.         if (module->create_loc_conf) {
  30.             ctx->loc_conf[ngx_modules[i]->ctx_index] =
  31.                                                    module->create_loc_conf(cf);
  32.             if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
  33.                  return NGX_CONF_ERROR;
  34.             }
  35.         }
  36.     }

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

  39.     value = cf->args->elts;

  40.     if (cf->args->nelts == 3) {

  41.         len = value[1].len;
  42.         mod = value[1].data;
  43.         name = &value[2];

  44.         if (len == 1 && mod[0] == '=') { // location = /a/b

  45.             clcf->name = *name;
  46.             clcf->exact_match = 1;

  47.         } else if (len == 2 && mod[0] == '^' && mod[1] == '~') { // location ^~ /a/b

  48.             clcf->name = *name;
  49.             clcf->noregex = 1;

  50.         } else if (len == 1 && mod[0] == '~') { // location ~ /a/b

  51.             if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
  52.                 return NGX_CONF_ERROR;
  53.             }

  54.         } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {// location = /a/b

  55.             if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
  56.                 return NGX_CONF_ERROR;
  57.             }

  58.         } else {
  59.             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  60.                                "invalid location modifier \"%V\"", &value[1]);
  61.             return NGX_CONF_ERROR;
  62.         }

  63.     } else {

  64.         name = &value[1];

  65.         if (name->data[0] == '=') {

  66.             clcf->name.len = name->len - 1;
  67.             clcf->name.data = name->data + 1;
  68.             clcf->exact_match = 1;

  69.         } else if (name->data[0] == '^' && name->data[1] == '~') {

  70.             clcf->name.len = name->len - 2;
  71.             clcf->name.data = name->data + 2;
  72.             clcf->noregex = 1;

  73.         } else if (name->data[0] == '~') {

  74.             name->len--;
  75.             name->data++;

  76.             if (name->data[0] == '*') {

  77.                 name->len--;
  78.                 name->data++;

  79.                 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
  80.                     return NGX_CONF_ERROR;
  81.                 }

  82.             } else {
  83.                 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
  84.                     return NGX_CONF_ERROR;
  85.                 }
  86.             }

  87.         } else {

  88.             clcf->name = *name;

  89.             if (name->data[0] == '@') {
  90.                 clcf->named = 1;
  91.             }
  92.         }
  93.     }

  94.     pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];

  95.     if (pclcf->name.len) {

  96.         /* nested location */

  97. #if 0
  98.         clcf->prev_location = pclcf;
  99. #endif

  100.         if (pclcf->exact_match) {
  101.             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  102.                                "location \"%V\" cannot be inside "
  103.                                "the exact location \"%V\"",
  104.                                &clcf->name, &pclcf->name);
  105.             return NGX_CONF_ERROR;
  106.         }

  107.         if (pclcf->named) {
  108.             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  109.                                "location \"%V\" cannot be inside "
  110.                                "the named location \"%V\"",
  111.                                &clcf->name, &pclcf->name);
  112.             return NGX_CONF_ERROR;
  113.         }

  114.         if (clcf->named) {
  115.             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  116.                                "named location \"%V\" can be "
  117.                                "on the server level only",
  118.                                &clcf->name);
  119.             return NGX_CONF_ERROR;
  120.         }

  121.         len = pclcf->name.len;

  122. #if (NGX_PCRE)
  123.         if (clcf->regex == NULL
  124.             && ngx_filename_cmp(clcf->name.data, pclcf->name.data, len) != 0)
  125. #else
  126.         if (ngx_filename_cmp(clcf->name.data, pclcf->name.data, len) != 0)
  127. #endif
  128.         {
  129.             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  130.                                "location \"%V\" is outside location \"%V\"",
  131.                                &clcf->name, &pclcf->name);
  132.             return NGX_CONF_ERROR;
  133.         }
  134.     }

  135.     if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
  136.         return NGX_CONF_ERROR;
  137.     }

  138.     // 保存父配置上下文信息
  139.     save = *cf;
  140.     // 设置该部分的配置上下文信息
  141.     cf->ctx = ctx;
  142.     cf->cmd_type = NGX_HTTP_LOC_CONF;

  143.     // 递归调用, 解析 'location' 配置块(子树)的配置命令
  144.     rv = ngx_conf_parse(cf, NULL);
  145.     // 至此,'location' 配置块(子树)的配置命令解析完毕

  146.     // 回复为父亲的配置上下文
  147.     *cf = save;

  148.     return rv;
  149. }

2.5 总结
可以看出,nginx的配置文件的解析处理是按照深度优先遍历配置文件的各个配置命令。

当ngx_http_block()中 ngx_conf_parse() 返回后,整个 'http'块(子树)的所有的配置命令解析完毕。此时,nginx保存的配置信息的内存布局如下图所示。

3. ngx_http_block 解析完http配置块后的处理
从代码以及图中可以看出,http层次既有main_conf,也有srv_conf、loc_conf;server层既有srv_conf,也有 loc_conf; location层,有 loc_conf,还可能有 nested locaton层的配置。这就需要把相关部分的配置信息进行合并。

点击(此处)折叠或打开

  1. static char *
  2. ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
  3. {
  4.     // http 配置块解析完毕
  5.     
  6.     if (rv != NGX_CONF_OK) {
  7.         goto failed;
  8.     }

  9.     /*
  10.      * init http{} main_conf's, merge the server{}s' srv_conf's
  11.      * and its location{}s' loc_conf's
  12.      */

  13.     cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
  14.     cscfp = cmcf->servers.elts;

  15.     for (m = 0; ngx_modules[m]; m++) {
  16.         if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
  17.             continue;
  18.         }

  19.         module = ngx_modules[m]->ctx;
  20.         mi = ngx_modules[m]->ctx_index;

  21.         /* init http{} main_conf's */

  22.         if (module->init_main_conf) {
  23.             rv = module->init_main_conf(cf, ctx->main_conf[mi]);
  24.             if (rv != NGX_CONF_OK) {
  25.                 goto failed;
  26.             }
  27.         }

  28.         // 合并server的配置信息,该函数会继续调用合并location的配置信息
  29.         rv = ngx_http_merge_servers(cf, cmcf, module, mi);//
  30.         if (rv != NGX_CONF_OK) {
  31.             goto failed;
  32.         }
  33.     }


  34.     /* create location trees */

  35.     // 对各个server下的location配置信息进行整理,其目的是后面对location进行查询时,
  36.     // 效率尽可能的高
  37.     for (s = 0; s < cmcf->servers.nelts; s++) {

  38.         // clcf鎸囧悜ngx_http_core_module鐨剆rv绾у埆鐨刲ocation淇℃伅
  39.         clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index];

  40.         // 后续blog进行分析
  41.         if (ngx_http_init_locations(cf, cscfp[s], clcf) != NGX_OK) {
  42.             return NGX_CONF_ERROR;
  43.         }

  44.         // 后续blog进行分析
  45.         if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) {
  46.             return NGX_CONF_ERROR;
  47.         }
  48.     }

  49.     // ngx把对 接受完http请求后的处理分为11个处理阶段,
  50.     // 也就是说可以在这个11个阶段注册各个模块的钩子函数,
  51.     // 使模块参与处理http业务。
  52.     if (ngx_http_init_phases(cf, cmcf) != NGX_OK) {
  53.         return NGX_CONF_ERROR;
  54.     }

  55.     
  56.     // cmcf->headers_in_hash
  57.     if (ngx_http_init_headers_in_hash(cf, cmcf) != NGX_OK) {
  58.         return NGX_CONF_ERROR;
  59.     }


  60.     for (m = 0; ngx_modules[m]; m++) {
  61.         if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
  62.             continue;
  63.         }

  64.         module = ngx_modules[m]->ctx;

  65.         if (module->postconfiguration) {
  66.             // 上面已经初始化好了各个阶段,
  67.             // 各个模块可以根据需要插入相应阶段的处理函数
  68.             if (module->postconfiguration(cf) != NGX_OK) {
  69.                 return NGX_CONF_ERROR;
  70.             }
  71.         }
  72.     }

  73.     if (ngx_http_variables_init_vars(cf) != NGX_OK) {
  74.         return NGX_CONF_ERROR;
  75.     }

  76.     /*
  77.      * http{}


至此整个http部分的配置解析完毕,理解了该部分配置信息的处理,其他配置信息可以很容易理解了。

 

阅读(2715) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~