The entire configuration analysis is mainly processed by the function ngx_init_cycle(&init_cycle). = ngx_create_pool(NGX_CYCLE_POOL_SIZE,log );//Allocate a 16k memory pool. The first node is about 16k. If a small memory node is added, the maximum node size is 4095. The context structure is stored in the corresponding structure of cycle->conf_ctx
The core module is as follows:
/* * 通过加锁和解锁,来更新如下时间 ngx_cached_time = tp; ngx_cached_http_time.data = p0; ngx_cached_err_log_time.data = p1; ngx_cached_http_log_time.data = p2; ngx_cached_http_log_iso8601.data = p3; */
nginx first created NGX_CORE_MODULE to pave the way for creating the subsequent module context, that is,
NGX_CORE_MODULE is the basis for other modules, as follows:
Among them, Ngx_errlog_module, ngx_events_module, and ngx_http_module modules do not have create_confThe method is based on The user's conf is actually created dynamically.
cycle->pool = pool; cycle->log = log; cycle->new_log.log_level = NGX_LOG_ERR; cycle->conf_prefix; //设置配置文件dir cycle->prefix; //设置运行环境dir cycle->conf_file; //设置配置文件绝对路径 cycle->conf_param; //保存参数 cycle->pathes; //路径数组 cycle->open_files; //分配打开的文件描述符,其中这个结构是一 个链表,每个链表节点都有一个n个size的 cycle->shared_memory; //分配n个共享内存节点,这个是一个list, 每个节点都存在n个ngx_shm_zone_t结构,通过next指向链表后面的节点。 cycle->listening; //listening数组 cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module*sizeof(void*));
Create parameters for conf, which are used to save the user configuration key and value of the configuration file. At the same time, create a
storage pool in temp_pool, conf->ctx points to cycle->conf_ctx, save cycle, pool, log, and set the module Type and command type,
Start parsing the main configuration file variables.
The process of parsing the configuration file is mainly an indirect recursive call by ngx_conf_parse, which is mainly divided into main scope, event scope, http scope, server scope, location scope, and then the analysis is carried out.
During the parsing process, the configuration file (nginx.conf) is divided into three categories:
NGX_CORE_MODULE index Ngx_core_module 0 Ngx_errlog_module 1 Ngx_reg_module 6 Ngx_events_module 3 Ngx_http_module 7
The above introduces [nginx source code analysis] configuration analysis 1, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.