解剖Nginx·模块开发篇(4)模块开发中的命名规则和模块加载与运行流程
2012-06-03 12:51
2366 查看
解剖Nginx·模块开发篇(4)模块开发中的命名规则和模块加载与运行流程
作者:柳大·Poechant(钟超)邮箱:zhongchao.ustc#gmail.com(# -> @)
博客:Blog.CSDN.net/Poechant
日期:June 2nd, 2012
1 命名规则
1.1 基本变量
基本变量有三个:ngx_module_t 类型的 ngx_http_foo_bar_module;ngx_command_t 类型的数组 ngx_http_foo_bar_commands;
ngx_http_module_t 类型的 ngx_http_foo_bar_module_ctx。
假设你开发了一个 Foo Bar 模块,那么模块名称应该叫:
ngx_http_foo_bar_module命令集合的名字的命名规则:
ngx_http_foo_bar_commands上下文的明子的命名规则:
ngx_http_foo_bar_module_ctx
1.2 基本类型
模块配置ngx_http_foo_bar_<main|srv|loc>_conf_t
2 加载与运行流程
这与 ngx_http_foo_bar_module_ctx 很有关系,它是 ngx_http_module_t 类型的,该类型定义如下:typedef struct { ngx_int_t (*preconfiguration)(ngx_conf_t *cf); ngx_int_t (*postconfiguration)(ngx_conf_t *cf); void *(*create_main_conf)(ngx_conf_t *cf); char *(*init_main_conf)(ngx_conf_t *cf, void *conf); void *(*create_srv_conf)(ngx_conf_t *cf); char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, void *conf); void *(*create_loc_conf)(ngx_conf_t *cf); char *(*merge_loc_conf)(ngx_conf_t *cf, void *prev, void *conf); } ngx_http_module_t;
2.1 preconfiguration
调用ngx_http_foo_bar_module_ctx.preconfiguration初始化 http 组件和 nginx 其他组件的交互;
2.2 解析配置文件
解析配置文件中的http模块。
http包含
server、
location等模块,所以在解析
http组件时,会根据具体的配置情况,多次调用
ngx_http_foo_bar_module_ctx.create_(srv|loc)_conf,创建 main_conf、srv_conf、loc_conf;
2.3 初始化 http 组件的 main 部分
调用ngx_http_foo_bar_module_ctx.init_main_conf初始化 main 组件;
2.4 merge
调用ngx_http_foo_bar_module_ctx.merge_srv_conf合并那些定义在“http”组件中的“server”组件配置。调用
ngx_http_foo_bar_module_ctx.merge_loc_conf合并那些定义在上层组件中的“location”配置;
2.5 postconfiguration
调用ngx_http_foo_bar_module_ctx.postconfigation初始化 http 组件和 nginx 其他组件的交互。-转载请注明来自柳大的CSDN博客:Blog.CSDN.net/Poechant-
相关文章推荐
- 解剖Nginx·模块开发篇(4)模块开发中的命名规则和模块加载与运行流程
- 解剖Nginx·模块开发篇(4)模块开发中的命名规则和模块加载与运行流程
- 解剖Nginx·模块开发篇(1)跑起你的 Hello World 模块!
- 解剖Nginx·模块开发篇(1)跑起你的 Hello World 模块!
- 解剖Nginx·模块开发篇(5)解读内置非默认模块 ngx_http_stub_status_module
- 解剖Nginx·模块开发篇(2)ngx_http_hello_world_module 模块基本结构定义
- 解剖Nginx·模块开发篇(3)ngx_http_hello_world_module 模块的基本函数实现
- 解剖Nginx·模块开发篇(2)ngx_http_hello_world_module 模块基本结构定义
- 解剖Nginx·模块开发篇(6)配置文件config入门
- 解剖Nginx·模块开发篇(3)ngx_http_hello_world_module 模块的基本函数实现
- 解剖Nginx·模块开发篇(6)配置文件config入门
- 解剖Nginx·模块开发篇(5)解读内置非默认模块 ngx_http_stub_status_module
- 解剖Nginx·模块开发篇(1)跑起你的 Hello World 模块!
- 解剖Nginx·模块开发篇(1)跑起你的 Hello World 模块!
- 内核模块编译、加载&卸载及查看运行结果 -- linux内核
- 解剖Nginx·自动脚本篇(1)解析配置选项脚本 auto/options
- 解剖 Nginx ·自动脚本篇(3)源码相关变量脚本 auto/sources
- 解剖Nginx·自动脚本篇(7)类型相关脚本系列
- 解剖 Nginx ·自动脚本篇(2)设置初始变量脚本 auto/init
- 解剖Nginx·自动脚本篇(5)编译器相关主脚本