【Nginx】http模块的数据结构
2014-07-05 20:32
211 查看
定义fttp模块方式很简单,比如:ngx_module_t ngx_http_mytest_module;
其中,ngx_module_t是一个Nginx模块的数据结构。
定义一个http模块时,务必把type字段设为NGX_HTTP_MODULE
定义http模块时,最重要的是要设置ctx和commands两个成员。对于http类型的模块来说,ngx_module_t中的ctx指针必须指向ngx_http_module_t接口。
http框架在读取、重载配置文件时定义了由ngx_http_module_t接口描述的8个阶段,http框架在启动过程中会在每个阶段中调用ngx_http_module_t中相应的方法,如果ngx_http_module_t中的某个回调方法设为NULL,那么HTTP框架是不会调用它的。
commands数组用于定义模块的配置文件参数,每一个数组元素都是ngx_command_t类型,数组的结尾用ngx_null_command表示。
其中,ngx_module_t是一个Nginx模块的数据结构。
typedef struct ngx_module_s ngx_module_t; struct ngx_module_s { #define NGX_MODULE_V1;//下面七个变量不需要在定义时赋值,由该宏来定义 ngx_uint_t ctx_index;//当前模块在这类模块中的序号 ngx_uint_t index;//当前模块在所有模块中的序号 ngx_uint_t spare0; ngx_uint_t spare1; ngx_uint_t spare2; ngx_uint_t spare3; ngx_uint_t version; void *ctx;//指向特定类型模块的公共接口,在http模块中,ctx需要指向ngx_http_module_t结构体 ngx_command_t *commands;//处理nginx.conf中的配置项 ngx_uint_t type;//该模块的类型 //... };
定义一个http模块时,务必把type字段设为NGX_HTTP_MODULE
定义http模块时,最重要的是要设置ctx和commands两个成员。对于http类型的模块来说,ngx_module_t中的ctx指针必须指向ngx_http_module_t接口。
http框架在读取、重载配置文件时定义了由ngx_http_module_t接口描述的8个阶段,http框架在启动过程中会在每个阶段中调用ngx_http_module_t中相应的方法,如果ngx_http_module_t中的某个回调方法设为NULL,那么HTTP框架是不会调用它的。
commands数组用于定义模块的配置文件参数,每一个数组元素都是ngx_command_t类型,数组的结尾用ngx_null_command表示。
typedef struct ngx_command_s ngx_command_t; struct ngx_command_s { ngx_str_t name;//配置项名称 ngx_uint_t type;//配置项类型 char *(*set)(ngx_conf_t *cf,ngx_command_t *cmd,void *conf);//处理name对应配置项参数 ngx_uint_t conf; ngx_uint_t offset; void *post;//配置项读取后的处理方法 }; #define ngx_null_command {ngx_null_string,0,null,0,0,null}
相关文章推荐
- nginx-http模块的数据结构
- Nginx的HTTP模块介绍-----数据结构部分
- nginx数据推送模块 - nginx http push module
- nginx 整合 ngx_http_accesskey_module 模块的应用
- nginx源码分析(2)——http模块的初始化过程
- 详细解释:nginx中ngx_http_auth_basic_module模块(HTTP Auth Basic 模块)配置及各个参数含义 .
- 详细解释:nginx中ngx_http_access_module模块(HTTP Access 模块)配置及各个参数含义
- nginx 动态缩略图模块安装(ngx_http_image_filter_module)
- Nginx Http模块开发
- nginx模块学习——nginx_http_push_module模块深入讲解和聊天室实现
- 解剖Nginx·模块开发篇(5)解读内置非默认模块 ngx_http_stub_status_module
- nginx图片过滤处理模块http_image_filter_module安装配置笔记
- Nginx服务器工作状态ngx_http_stub_status_module 模块
- 高性能Web服务器Nginx的配置与部署研究(10)核心模块之HTTP模块Location相关指令
- 高性能Web服务器Nginx的配置与部署研究(9)核心模块之HTTP模块基本常用指令
- nginx模块学习——nginx_http_push_module模块深入讲解和聊天室实现
- Nginx Http模块开发
- nginx版本变化引起的自定义http模块的运行异常
- 高性能Web服务器Nginx的配置与部署研究(9)核心模块之HTTP模块基本常用指令
- 详细解释:nginx中ChsHttpProxyModule模块各项配置及其含义