《Nginx高性能Web服务器详解》第11章Nginx基本数据结构,本章开始,我们学习Nginx源码的具体实现。学习体系错综复杂、功能服务实现丰富的Nginx服务器源码,应该从整个源码体系赖以存在的基本元素--数据结构开始学起。本节为大家介绍ngx_conf_s结构体。
作者:苗泽来源:电子工业出版社|2013-12-02 11:43
11.9 ngx_conf_s结构体
该结构体用于Nginx在解析配置文件时描述每个指令的属性,也是Nginx程序中非常重要的一个数据结构,我们在/nginx/src/core/ngx_conf_file.h文件中可以找到它的定义:
- struct ngx_conf_s {
- char *name;
- ngx_array_t *args;
- ngx_cycle_t *cycle;
- ngx_pool_t *pool;
- ngx_pool_t *temp_pool;
- ngx_conf_file_t *conf_file;
- ngx_log_t *log;
- void *ctx;
- ngx_uint_t module_type;
- ngx_uint_t cmd_type;
- ngx_conf_handler_pt handler;
- char *handler_conf;
- };
*name,存放当前解析到的指令。
*args,存放该指令包含的所有参数。
*cycle,参见11.8节"ngx_cycle_s结构体"。
*pool,参见11.4节"ngx_pool_s结构体"。
*temp_pool,用于解析配置文件的临时内存池,解析完成后释放。其结构体类型的细节参见11.4节"ngx_pool_s结构体"。
*conf_file,存放Nginx配置文件的相关信息。ngx_conf_file_t结构体的定义我们在该文件中也能找到:
- typedef struct {
- ngx_file_t file; //文件的属性
- ngx_buf_t *buffer; //文件的内容
- ngx_uint_t line; //文件的行数
- } ngx_conf_file_t;
*log,描述日志文件的相关属性。
*ctx,描述指令的上下文。
module_type,支持该指令的模块的类型,core、http、event和mail中的一种。
cmd_type,指令的类型。
handler,指令自定义的处理函数。
*handler_conf,自定义处理函数需要的相关配置。