zoukankan      html  css  js  c++  java
  • 解剖Nginx·模块开发篇(4)模块开发中的命名规则和模块加载与运行流程

    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包含serverlocation等模块,所以在解析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 其他组件的交互。

    -

  • 相关阅读:
    ASP.NET 2.0 中动态添加 GridView 模板列的例子
    ASP操作Excel技术总结
    JS实现下拉列表效果
    发布无限制版CodePlusV2.0(转载)
    SQL行列转换(转载)
    [转]详解C中volatile关键字
    [转]68013开发笔记之一
    清除计算机占用串口
    modelsim保存仿真波形
    SQL存储过程分页算法研究(支持千万级) 转
  • 原文地址:https://www.cnblogs.com/breg/p/4043658.html
Copyright © 2011-2022 走看看