zoukankan      html  css  js  c++  java
  • 【Nginx】http模块的数据结构

    定义fttp模块方式很简单,比如:ngx_module_t ngx_http_mytest_module;

    其中,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}
  • 相关阅读:
    2-SAT模板
    AC自动机
    省选预备营-Day3(图论) 总结
    省选预备营-Day2(分治) 总结
    左偏树(可并堆)总结
    省选预备营-Day1(数据结构) 总结
    OI基础知识
    C++ 堆
    CH4601 普通平衡树
    java 函数形参传值和传引用的区别
  • 原文地址:https://www.cnblogs.com/ljygoodgoodstudydaydayup/p/3826387.html
Copyright © 2011-2022 走看看