首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

nginx模块开发入门(5)-2.4 The Module Definition

2013-10-16 
nginx模块开发入门(五)-2.4 The Module Definition2.4. 模块定义(The Module Definition)接下来我们间接地

nginx模块开发入门(五)-2.4 The Module Definition
2.4. 模块定义(The Module Definition)

   接下来我们间接地介绍更深一层:结构体ngx_module_t。该结构体变量命名方式为ngx_http_<module name>_module。它包含模块的内容和指令执行方式,同时也还包含一些回调函数(退出线程,退出进程,等等)。模块定义在有的时候会被用作查找的关键字,来查找与特定模块相关联的数据。模块定义通常像是这样:

ngx_module_t  ngx_http_<module name>_module = {    NGX_MODULE_V1,    &ngx_http_<module name>_module_ctx, /* module context */    ngx_http_<module name>_commands,   /* module directives */    NGX_HTTP_MODULE,               /* module type */    NULL,                          /* init master */    NULL,                          /* init module */    NULL,                          /* init process */    NULL,                          /* init thread */    NULL,                          /* exit thread */    NULL,                          /* exit process */    NULL,                          /* exit master */    NGX_MODULE_V1_PADDING};

    ...仅仅替换掉合适的<module name>就可以了。模块可以添加一些回调函数来处理 线程/进程 的创建和销毁,但是绝大多数模块都用NULL忽略这些东东。(关于这些回调函数的入参,可以参考 core/ngx_conf_file.h.)

2.5. 模块装载(Module Installation)

    模块的装载方式取决于模块的类型:handler、filter还是load-balancer。所以具体的装载细节将留在其各自的章节中再做介绍。

热点排行