当前位置: 首页 > news >正文

nginx的ngx_module_s 模块

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

特点:module和command:

  • 所有的模块结构都是全局变量
  • module是配置的内存结构,所有的配置都存放在cycle->ctx中
  • command是配置文件的解析函数:block、指令值。
    • 解析配置文件的时候,调用指令解析函数cmd->set() 的方式解析值,替换其上下文配置。
    • 一般在指令读取时,遇见block,会将下级模块都初始化(即{}中的上下文配置初始化)

模块加载:在ngx_cycle_init()中

  • 在nginx被make之后,会直接创建一个ngx_names[]数组的动态库,然后通过dlope()将所有模块都加入进去
  • 在初始化cycle的时候,,在ngx_init_cycle()中,会将 NGX_CORE_MODULE类型的module通过 create_conf()初始化这些模块上下文ctx的地址空间
    • 例如:log、http、mail、stream、events的 create_conf() = NULL && init_conf() = NULL
    • 例如: openssl、thread_pool、regex存在create_conf()
/**
    regex模块分配空间,并设为默认值
*/
static void *
ngx_regex_create_conf(ngx_cycle_t *cycle)
{
    ngx_regex_conf_t  *rcf;

    rcf = ngx_pcalloc(cycle->pool, sizeof(ngx_regex_conf_t));
    if (rcf  NULL) {
        return NULL;
    }

    rcf->pcre_jit = NGX_CONF_UNSET;

    ngx_pcre_studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t));
    if (ngx_pcre_studies  NULL) {
        return NULL;
    }

    return rcf;
}
  • 读取配置文件,通过command将需要的初始化和设置二级模块创建,如果没有遇见一级模块指令。

    • 例如:遇见一级events指令,则调用它的指令解析函数:ngx_events_block()
      • 初始化其二级模块 (NGX_EVENT_MODULE类型) 的上下文配置create_conf() = ngx_event_core_create_conf(),因为不知道哪个模块将在配置中,需要给所有的这类模块(编译时已加载)分配内存空间
        • 初始化ngx_event_core_module的配置空间:ngx_event_core_create_conf()初始化下级模块
        • 初始化ngx_epoll_module的配置空间:ngx_epoll_create_conf()
        • 初始化ngx_devpoll_module的配置空间:ngx_devpoll_create_conf()
        • 初始化ngx_eventport_module的配置空间:ngx_epoll_create_conf()
        • 初始化ngx_iocp_module的配置空间:ngx_iocp_create_conf()
        • 初始化ngx_kqueue_module的配置空间:ngx_kqueue_create_conf()
        • 初始化ngx_poll_module的配置空间:NULL
        • 初始化ngx_select_module的配置空间:NULL()
        • 初始化win32的ngx_select_module的配置空间:NULL()
      • 继续解析文件:ngx_conf_parse(),解析 events{} 中的各指令,替换二级模块上下文配置值
        • 遇见 (use epoll;),设置ngx_event_core_module模块(event_core模块)的上下文(ngx_event_init_conf)ctx.name=epoll
        • 遇见 (worker_connections 1024;),设置ngx_event_core_module模块(event_core模块)的上下文(ngx_event_init_conf)ctx.connections=1024
      • 调用ngx_event_core_module模块的 init_conf() = ngx_event_core_init_conf(),将没有初始化的参数初始化
      • 调用ngx_epoll_module模块的 init_conf() = ngx_epoll_init_conf(),将没有初始化的参数初始化
  • 检测NGX_CORE_MODULE模块的init_conf()来将上下文配置中没有设置参数,设置为默认值

    • 例如:log、http、mail、stream的init_conf() = NULL
    • 例如:events的init_conf() = ngx_event_init_conf()
  • 完成配置模块上下文配置的初始化,在ngx_worker_process_init() 中调用模块的 init_process() 启动上面初始化的模块(不过在源码中只有 nginx_event_core_module有这个启动函数ngx_event_process_init(),其它模块都是NULL)

/**
    初始化二级模块(NGX_EVENT_MODULE类型)ngx_event_core_module模块的上下文配置
*/
static void *
ngx_event_core_create_conf(ngx_cycle_t *cycle)
{
    ngx_event_conf_t  *ecf;

    ecf = ngx_palloc(cycle->pool, sizeof(ngx_event_conf_t));
    if (ecf  NULL) {
        return NULL;
    }

    ecf->connections = NGX_CONF_UNSET_UINT;
    ecf->use = NGX_CONF_UNSET_UINT;
    ecf->multi_accept = NGX_CONF_UNSET;
    ecf->accept_mutex = NGX_CONF_UNSET;
    ecf->accept_mutex_delay = NGX_CONF_UNSET_MSEC;
    ecf->name = (void *) NGX_CONF_UNSET;
    return ecf;
}
/***
    根据配置的信息来启用(NGX_EVENT_MODULE类型)ngx_event_core_module剩下的上下文配置信息,并将其设置到cycle上
*/
static char *
ngx_event_core_init_conf(ngx_cycle_t *cycle, void *conf)
{
    ngx_event_conf_t  *ecf = conf;

    int                  fd;
    ngx_int_t            i;
    ngx_module_t        *module;
    ngx_event_module_t  *event_module;

    module = NULL;
    '根据编译的时候,启动了epoll、select、etc其中一种'
    #if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)
    
        fd = epoll_create(100);
    
        if (fd != -1) {
            (void) close(fd);
            module = &ngx_epoll_module;
    
        } else if (ngx_errno != NGX_ENOSYS) {
            module = &ngx_epoll_module;
        }
    
    #endif
    
    #if (NGX_HAVE_DEVPOLL) && !(NGX_TEST_BUILD_DEVPOLL)
    
        module = &ngx_devpoll_module;
    
    #endif
    
    #if (NGX_HAVE_KQUEUE)
    
        module = &ngx_kqueue_module;
    
    #endif
    
    #if (NGX_HAVE_SELECT)
    
        if (module  NULL) {
            module = &ngx_select_module;
        }
    
    #endif
    // 所有的 ngx_epoll_module 模块
    if (module  NULL) {
        for (i = 0; cycle->modules[i]; i++) {

            if (cycle->modules[i]->type != NGX_EVENT_MODULE) {
                continue;
            }

            event_module = cycle->modules[i]->ctx;

            if (ngx_strcmp(event_module->name->data, event_core_name.data)  0)
            {
                continue;
            }

            module = cycle->modules[i];
            break;
        }
    }

    if (module  NULL) {
        ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "no events module found");
        return NGX_CONF_ERROR;
    }

    ngx_conf_init_uint_value(ecf->connections, DEFAULT_CONNECTIONS);
    cycle->connection_n = ecf->connections;

    ngx_conf_init_uint_value(ecf->use, module->ctx_index);

    event_module = module->ctx;
    ngx_conf_init_ptr_value(ecf->name, event_module->name->data);

    ngx_conf_init_value(ecf->multi_accept, 0);
    ngx_conf_init_value(ecf->accept_mutex, 0);
    ngx_conf_init_msec_value(ecf->accept_mutex_delay, 500);

    return NGX_CONF_OK;
}
/**
    初始化二级模块(NGX_EVENT_MODULE类型)ngx_epoll_module的上下文配置
*/
static void *
ngx_epoll_create_conf(ngx_cycle_t *cycle)
{
    ngx_epoll_conf_t  *epcf;

    epcf = ngx_palloc(cycle->pool, sizeof(ngx_epoll_conf_t));
    if (epcf  NULL) {
        return NULL;
    }

    epcf->events = NGX_CONF_UNSET;
    epcf->aio_requests = NGX_CONF_UNSET;

    return epcf;
}
/**
    设置二级模块(NGX_EVENT_MODULE类型)ngx_epoll_module的上下文配置
*/
static char *
ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf)
{
    ngx_epoll_conf_t *epcf = conf;

    ngx_conf_init_uint_value(epcf->events, 512);
    ngx_conf_init_uint_value(epcf->aio_requests, 32);

    return NGX_CONF_OK;
}

ngx_module_s:模块结构

struct ngx_module_s {
    ngx_uint_t            ctx_index;    '模块初始化内存的回调函数的索引,ngx_conf_s.ctx中的位置'
    ngx_uint_t            index;        '模块初始化内存的回调函数的索引,ngx_conf_s.ctx中的位置'

    char                 *name;         //模块名称

    ngx_uint_t            spare0;
    ngx_uint_t            spare1;

    ngx_uint_t            version;      //模块版本
    const char           *signature;

    'core模块的上下文:名称,模块和命令基本信息的创建、初始化回调函数'
    void                 *ctx; 
    '指令上下文:名称基本信息的初始化回调函数'
    ngx_command_t        *commands;     
    ngx_uint_t            type;         //该模块实例的类型标识core,http,event和mail,

    ngx_int_t           (*init_master)(ngx_log_t *log); //主进程初始化时调用

    ngx_int_t           (*init_module)(ngx_cycle_t *cycle); //模块初始化时调用

    ngx_int_t           (*init_process)(ngx_cycle_t *cycle);    //工作进程初始化时调用
    ngx_int_t           (*init_thread)(ngx_cycle_t *cycle);     //线程初始化时调用
    void                (*exit_thread)(ngx_cycle_t *cycle);     //线程退出时调用
    void                (*exit_process)(ngx_cycle_t *cycle);    //工作进程退出时调用

    void                (*exit_master)(ngx_cycle_t *cycle);     //主进程退出时调用
    //以下是预留成员
    uintptr_t             spare_hook0;
    uintptr_t             spare_hook1;
    uintptr_t             spare_hook2;
    uintptr_t             spare_hook3;
    uintptr_t             spare_hook4;
    uintptr_t             spare_hook5;
    uintptr_t             spare_hook6;
    uintptr_t             spare_hook7;
};
  • type值
模块类型类型模块名称指令
NGX_CORE_MODULEerrlogerror_log
NGX_CORE_MODULEthread_poolthread_pool
NGX_CORE_MODULEopensslssl_engine
NGX_CORE_MODULEhttphttp
NGX_CORE_MODULEmailmail
NGX_CORE_MODULEgoogle_perftoolsgoogle_perftools_profiles
NGX_CORE_MODULEstreamstream
NGX_CORE_MODULEcoredaemon、master_process、timer_resolution、pid、lock_file、worker_processes、debug_points、user、worker_priority、worker_cpu_affinity、worker_rlimit_nofile、worker_rlimit_core、worker_shutdown_timeout、working_directory、env、load_module
NGX_CONF_MODULENULLinclude
  • *ctx参数在读取配置文件遇见 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS 这种block指令时,替换掉。
ngx_core_module_t:核心模块
typedef struct {
    ngx_str_t             name;
    void               *(*create_conf)(ngx_cycle_t *cycle);
    char               *(*init_conf)(ngx_cycle_t *cycle, void *conf);
} ngx_core_module_t;

ngx_command_s :指令结构

struct ngx_command_s {
    ngx_str_t             name;     //指令名称
    ngx_uint_t            type;     // 指令类型
    //配置文件的指令解析函数
    char               *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 
    //该字段被NGX_HTTP_MODULE类型模块所用 (我们编写的基本上都是NGX_HTTP_MOUDLE,只有一些nginx核心模块是非NGX_HTTP_MODULE),该字段指定当前配置项存储的内存位置。
    //实际上是使用哪个内存池的问题。实际上是使用哪个内存池的问题。因为http模块对所有http模块所要保存的配置信息,划分了main, server和location三个地方进行存储,每个地方都有一个内存池用来分配存储这些信息的内存。
    //这里可能的值为 NGX_HTTP_MAIN_CONF_OFFSET、NGX_HTTP_SRV_CONF_OFFSET或NGX_HTTP_LOC_CONF_OFFSET。当然也可以直接置为0,就是NGX_HTTP_MAIN_CONF_OFFSET。
    ngx_uint_t            conf;     
    //指定该配置项值的精确存放位置,一般指定为某一个结构体变量的字段偏移。
    //因为对于配置信息的存储,一般我们都是定义个结构体来存储的。那么比如我们定义了一个结构体A,该项配置的值需要存储到该结构体的b字段。
    // 那么在这里就可以填写为offsetof(A, b)。对于有些配置项,它的值不需要保存或者是需要保存到更为复杂的结构中时,这里可以设置为0
    ngx_uint_t            offset;   
    void                 *post;     //该字段存储一个指针。可以指向任何一个在读取配置过程中需要的数据,以便于进行配置读取的处理。大多数时候,都不需要,所以简单地设为0即可。
};

  • 指令类型type:
指令类型说明
NGX_MAIN_CONF例如:http、mail、events、error_log等
NGX_DIRECT_CONF可以出现在配置文件中最外层。例如已经提供的配置指令daemon,master_process等
NGX_ANY_CONF该配置指令可以出现在任意配置级别上
NGX_MAIN_CONFhttp、mail、events、error_log等
NGX_CONF_BLOCK配置指令可以接受的值是一个配置信息块。也就是一对大括号括起来的内容。里面可以再包括很多的配置指令。比如常见的server指令就是这个属性的
NGX_CONF_FLAG配置指令可以接受的值是”on”或者”off”,最终会被转成bool值
NGX_CONF_ANY配置指令可以接受的任意的参数值。一个或者多个,或者”on”或者”off”,或者是配置块
NGX_CONF_ANY配置指令可以接受的任意的参数值。一个或者多个,或者”on”或者”off”,或者是配置块
HTTP模块
NGX_HTTP_MAIN_CONF可以直接出现在http配置指令里
NGX_HTTP_SRV_CONF可以出现在http里面的server配置指令里
NGX_HTTP_LOC_CONF可以出现在http server块里面的location配置指令里
NGX_HTTP_UPS_CONF可以出现在http里面的upstream配置指令里
NGX_HTTP_SIF_CONF可以出现在http里面的server配置指令里的if语句所在的block中
NGX_HTTP_LMT_CONF可以出现在http里面的limit_except指令的block中
NGX_HTTP_LMT_CONF可以出现在http里面的limit_except指令的block中
NGX_HTTP_LMT_CONF可以出现在http里面的limit_except指令的block中
NGX_HTTP_LIF_CONF可以出现在http server块里面的location配置指令里的if语句所在的block中
nginx的配置指令的参数个数不可以超过NGX_CONF_MAX_ARGS个,目前这个值被定义为8,也就是不能超过8个参数值
NGX_CONF_NOARGS配置指令不接受任何参数
NGX_CONF_TAKE1配置指令接受1个参数
NGX_CONF_TAKE2配置指令接受2个参数
NGX_CONF_TAKE3配置指令接受3个参数
NGX_CONF_TAKE4配置指令接受4个参数
NGX_CONF_TAKE5配置指令接受5个参数
NGX_CONF_TAKE6配置指令接受6个参数
NGX_CONF_TAKE8配置指令接受7个参数
NGX_CONF_TAKE12配置指令接受1个或者2个参数
NGX_CONF_TAKE13配置指令接受1个或者3个参数
NGX_CONF_TAKE23配置指令接受2个或者3个参数
NGX_CONF_TAKE123配置指令接受1个或者2个或者3参数
NGX_CONF_TAKE1234配置指令接受1个或者2个或者3个或者4个参数
NGX_CONF_1MORE配置指令接受至少一个参数
NGX_CONF_2MORE配置指令接受至少两个参数
NGX_CONF_MULTI配置指令可以接受多个参数,即个数不定。
NGX_CONF_2MORE配置指令接受至少两个参数
NGX_CONF_2MORE配置指令接受至少两个参数

实例:core模块加载

ngx_core_module
ngx_module_t  ngx_core_module = {
    NGX_MODULE_V1,
    &ngx_core_module_ctx,                  /* module context */
    ngx_core_commands,                     /* module directives */
    NGX_CORE_MODULE,                       /* module type */    //NGX_CORE_MODULE      0x45524F43
    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
};
// NGX_MODULE_V1
#define NGX_MODULE_V1                    
    NGX_MODULE_UNSET_INDEX, //  ngx_module_s.ctx_index = NGX_MODULE_UNSET_INDEX  (ngx_uint_t) -1
    NGX_MODULE_UNSET_INDEX, //  ngx_module_s.index = NGX_MODULE_UNSET_INDEX  (ngx_uint_t) -1                    
    NULL,                   //  ngx_module_s.name
    0,                      //  ngx_module_s.spare0
    0,                      //  ngx_module_s.spare1
    nginx_version,          //  ngx_module_s.nginx_version
    NGX_MODULE_SIGNATURE    //  ngx_module_s.signature

// 上个信号:NGX_MODULE_SIGNATURE
#define NGX_MODULE_SIGNATURE                                                  \
    NGX_MODULE_SIGNATURE_0 NGX_MODULE_SIGNATURE_1 NGX_MODULE_SIGNATURE_2      \
    NGX_MODULE_SIGNATURE_3 NGX_MODULE_SIGNATURE_4 NGX_MODULE_SIGNATURE_5      \
    NGX_MODULE_SIGNATURE_6 NGX_MODULE_SIGNATURE_7 NGX_MODULE_SIGNATURE_8      \
    NGX_MODULE_SIGNATURE_9 NGX_MODULE_SIGNATURE_10 NGX_MODULE_SIGNATURE_11    \
    NGX_MODULE_SIGNATURE_12 NGX_MODULE_SIGNATURE_13 NGX_MODULE_SIGNATURE_14   \
    NGX_MODULE_SIGNATURE_15 NGX_MODULE_SIGNATURE_16 NGX_MODULE_SIGNATURE_17   \
    NGX_MODULE_SIGNATURE_18 NGX_MODULE_SIGNATURE_19 NGX_MODULE_SIGNATURE_20   \
    NGX_MODULE_SIGNATURE_21 NGX_MODULE_SIGNATURE_22 NGX_MODULE_SIGNATURE_23   \
    NGX_MODULE_SIGNATURE_24 NGX_MODULE_SIGNATURE_25 NGX_MODULE_SIGNATURE_26   \
    NGX_MODULE_SIGNATURE_27 NGX_MODULE_SIGNATURE_28 NGX_MODULE_SIGNATURE_29   \
    NGX_MODULE_SIGNATURE_30 NGX_MODULE_SIGNATURE_31 NGX_MODULE_SIGNATURE_32   \
    NGX_MODULE_SIGNATURE_33 NGX_MODULE_SIGNATURE_34

// NGX_MODULE_V1_PADDING
#define NGX_MODULE_V1_PADDING  
    0,          // ngx_module_s.spare_hook0
    0,          // ngx_module_s.spare_hook1
    0,          // ngx_module_s.spare_hook2
    0,          // ngx_module_s.spare_hook3
    0,          // ngx_module_s.spare_hook4
    0,          // ngx_module_s.spare_hook5
    0,          // ngx_module_s.spare_hook6
    0           // ngx_module_s.spare_hook7
动态加载模块:
  • configure生成一个咋objs/ngx_modules.c

#include <ngx_config.h>
#include <ngx_core.h>



extern ngx_module_t  ngx_core_module;
extern ngx_module_t  ngx_errlog_module;
extern ngx_module_t  ngx_conf_module;
extern ngx_module_t  ngx_openssl_module;
extern ngx_module_t  ngx_regex_module;
extern ngx_module_t  ngx_events_module;
extern ngx_module_t  ngx_event_core_module;
extern ngx_module_t  ngx_epoll_module;
extern ngx_module_t  ngx_http_module;
extern ngx_module_t  ngx_http_core_module;
extern ngx_module_t  ngx_http_log_module;
extern ngx_module_t  ngx_http_upstream_module;
extern ngx_module_t  ngx_http_static_module;
extern ngx_module_t  ngx_http_autoindex_module;
extern ngx_module_t  ngx_http_index_module;
extern ngx_module_t  ngx_http_auth_basic_module;
extern ngx_module_t  ngx_http_access_module;
extern ngx_module_t  ngx_http_limit_conn_module;
extern ngx_module_t  ngx_http_limit_req_module;
extern ngx_module_t  ngx_http_geo_module;
extern ngx_module_t  ngx_http_map_module;
extern ngx_module_t  ngx_http_split_clients_module;
extern ngx_module_t  ngx_http_referer_module;
extern ngx_module_t  ngx_http_rewrite_module;
extern ngx_module_t  ngx_http_ssl_module;
extern ngx_module_t  ngx_http_proxy_module;
extern ngx_module_t  ngx_http_fastcgi_module;
extern ngx_module_t  ngx_http_uwsgi_module;
extern ngx_module_t  ngx_http_scgi_module;
extern ngx_module_t  ngx_http_memcached_module;
extern ngx_module_t  ngx_http_empty_gif_module;
extern ngx_module_t  ngx_http_browser_module;
extern ngx_module_t  ngx_http_upstream_hash_module;
extern ngx_module_t  ngx_http_upstream_ip_hash_module;
extern ngx_module_t  ngx_http_upstream_least_conn_module;
extern ngx_module_t  ngx_http_upstream_keepalive_module;
extern ngx_module_t  ngx_http_upstream_zone_module;
extern ngx_module_t  ndk_http_module;
extern ngx_module_t  ngx_coolkit_module;
extern ngx_module_t  ngx_http_set_misc_module;
extern ngx_module_t  ngx_http_form_input_module;
extern ngx_module_t  ngx_http_encrypted_session_module;
extern ngx_module_t  ngx_http_lua_upstream_module;
extern ngx_module_t  ngx_http_array_var_module;
extern ngx_module_t  ngx_http_memc_module;
extern ngx_module_t  ngx_http_redis2_module;
extern ngx_module_t  ngx_http_redis_module;
extern ngx_module_t  ngx_http_write_filter_module;
extern ngx_module_t  ngx_http_header_filter_module;
extern ngx_module_t  ngx_http_chunked_filter_module;
extern ngx_module_t  ngx_http_range_header_filter_module;
extern ngx_module_t  ngx_http_gzip_filter_module;
extern ngx_module_t  ngx_http_postpone_filter_module;
extern ngx_module_t  ngx_http_ssi_filter_module;
extern ngx_module_t  ngx_http_charset_filter_module;
extern ngx_module_t  ngx_http_userid_filter_module;
extern ngx_module_t  ngx_http_headers_filter_module;
extern ngx_module_t  ngx_http_echo_module;
extern ngx_module_t  ngx_http_xss_filter_module;
extern ngx_module_t  ngx_http_srcache_filter_module;
extern ngx_module_t  ngx_http_lua_module;
extern ngx_module_t  ngx_http_headers_more_filter_module;
extern ngx_module_t  ngx_http_rds_json_filter_module;
extern ngx_module_t  ngx_http_rds_csv_filter_module;
extern ngx_module_t  ngx_http_copy_filter_module;
extern ngx_module_t  ngx_http_range_body_filter_module;
extern ngx_module_t  ngx_http_not_modified_filter_module;

ngx_module_t *ngx_modules[] = {
    &ngx_core_module,
    &ngx_errlog_module,
    &ngx_conf_module,
    &ngx_openssl_module,
    &ngx_regex_module,
    &ngx_events_module,
    &ngx_event_core_module,
    &ngx_epoll_module,
    &ngx_http_module,
    &ngx_http_core_module,
    &ngx_http_log_module,
    &ngx_http_upstream_module,
    &ngx_http_static_module,
    &ngx_http_autoindex_module,
    &ngx_http_index_module,
    &ngx_http_auth_basic_module,
    &ngx_http_access_module,
    &ngx_http_limit_conn_module,
    &ngx_http_limit_req_module,
    &ngx_http_geo_module,
    &ngx_http_map_module,
    &ngx_http_split_clients_module,
    &ngx_http_referer_module,
    &ngx_http_rewrite_module,
    &ngx_http_ssl_module,
    &ngx_http_proxy_module,
    &ngx_http_fastcgi_module,
    &ngx_http_uwsgi_module,
    &ngx_http_scgi_module,
    &ngx_http_memcached_module,
    &ngx_http_empty_gif_module,
    &ngx_http_browser_module,
    &ngx_http_upstream_hash_module,
    &ngx_http_upstream_ip_hash_module,
    &ngx_http_upstream_least_conn_module,
    &ngx_http_upstream_keepalive_module,
    &ngx_http_upstream_zone_module,
    &ndk_http_module,
    &ngx_coolkit_module,
    &ngx_http_set_misc_module,
    &ngx_http_form_input_module,
    &ngx_http_encrypted_session_module,
    &ngx_http_lua_upstream_module,
    &ngx_http_array_var_module,
    &ngx_http_memc_module,
    &ngx_http_redis2_module,
    &ngx_http_redis_module,
    &ngx_http_write_filter_module,
    &ngx_http_header_filter_module,
    &ngx_http_chunked_filter_module,
    &ngx_http_range_header_filter_module,
    &ngx_http_gzip_filter_module,
    &ngx_http_postpone_filter_module,
    &ngx_http_ssi_filter_module,
    &ngx_http_charset_filter_module,
    &ngx_http_userid_filter_module,
    &ngx_http_headers_filter_module,
    &ngx_http_echo_module,
    &ngx_http_xss_filter_module,
    &ngx_http_srcache_filter_module,
    &ngx_http_lua_module,
    &ngx_http_headers_more_filter_module,
    &ngx_http_rds_json_filter_module,
    &ngx_http_rds_csv_filter_module,
    &ngx_http_copy_filter_module,
    &ngx_http_range_body_filter_module,
    &ngx_http_not_modified_filter_module,
    NULL
};

char *ngx_module_names[] = {
    "ngx_core_module",
    "ngx_errlog_module",
    "ngx_conf_module",
    "ngx_openssl_module",
    "ngx_regex_module",
    "ngx_events_module",
    "ngx_event_core_module",
    "ngx_epoll_module",
    "ngx_http_module",
    "ngx_http_core_module",
    "ngx_http_log_module",
    "ngx_http_upstream_module",
    "ngx_http_static_module",
    "ngx_http_autoindex_module",
    "ngx_http_index_module",
    "ngx_http_auth_basic_module",
    "ngx_http_access_module",
    "ngx_http_limit_conn_module",
    "ngx_http_limit_req_module",
    "ngx_http_geo_module",
    "ngx_http_map_module",
    "ngx_http_split_clients_module",
    "ngx_http_referer_module",
    "ngx_http_rewrite_module",
    "ngx_http_ssl_module",
    "ngx_http_proxy_module",
    "ngx_http_fastcgi_module",
    "ngx_http_uwsgi_module",
    "ngx_http_scgi_module",
    "ngx_http_memcached_module",
    "ngx_http_empty_gif_module",
    "ngx_http_browser_module",
    "ngx_http_upstream_hash_module",
    "ngx_http_upstream_ip_hash_module",
    "ngx_http_upstream_least_conn_module",
    "ngx_http_upstream_keepalive_module",
    "ngx_http_upstream_zone_module",
    "ndk_http_module",
    "ngx_coolkit_module",
    "ngx_http_set_misc_module",
    "ngx_http_form_input_module",
    "ngx_http_encrypted_session_module",
    "ngx_http_lua_upstream_module",
    "ngx_http_array_var_module",
    "ngx_http_memc_module",
    "ngx_http_redis2_module",
    "ngx_http_redis_module",
    "ngx_http_write_filter_module",
    "ngx_http_header_filter_module",
    "ngx_http_chunked_filter_module",
    "ngx_http_range_header_filter_module",
    "ngx_http_gzip_filter_module",
    "ngx_http_postpone_filter_module",
    "ngx_http_ssi_filter_module",
    "ngx_http_charset_filter_module",
    "ngx_http_userid_filter_module",
    "ngx_http_headers_filter_module",
    "ngx_http_echo_module",
    "ngx_http_xss_filter_module",
    "ngx_http_srcache_filter_module",
    "ngx_http_lua_module",
    "ngx_http_headers_more_filter_module",
    "ngx_http_rds_json_filter_module",
    "ngx_http_rds_csv_filter_module",
    "ngx_http_copy_filter_module",
    "ngx_http_range_body_filter_module",
    "ngx_http_not_modified_filter_module",
    NULL
};
  • 然后make生成一个 共享库:ngx_modules.o

这还有问题

  • 在启动的时候,初始化init_cycle,调用ngx_init_cycle
//加载模块的基本信息,解析配置文件时初始化
    if (ngx_cycle_modules(cycle) != NGX_OK) {
        ngx_destroy_pool(pool);
        return NULL;
    }


    for (i = 0; cycle->modules[i]; i++) {
        if (cycle->modules[i]->type != NGX_CORE_MODULE) {
            continue;
        }

        module = cycle->modules[i]->ctx;

        if (module->create_conf) {
            rv = module->create_conf(cycle);
            if (rv  NULL) {
                ngx_destroy_pool(pool);
                return NULL;
            }
            cycle->conf_ctx[cycle->modules[i]->index] = rv;
        }
    }

转载于:https://my.oschina.net/u/2246410/blog/1801302

相关文章:

  • 阿里云RDS-MYSQL数据库参数设置
  • k8s实验环境的快速搭建
  • IBM欲寻找量子杀手级应用
  • jQuery插件 -- Form表单插件jquery.form.js
  • 日志框架 - 基于spring-boot - 实现2 - 消息定义及消息日志打印
  • php命令行生成项目结构
  • P4035 [JSOI2008]球形空间产生器
  • 简述this指向
  • 如何理解angular自定义指令directive的scope属性?
  • zabbix3配置阿里云邮箱告警
  • 小葵花妈妈课堂开课了:《Runnable、Callable、Future、RunnableFuture、FutureTask 源码分析》...
  • 跟我学Shiro电子书
  • 嵌入式视觉应用的疆土在逐步扩大
  • requests 中文乱码
  • [原]Python安装和使用MySQLdb库(Windows系统)
  • 【笔记】你不知道的JS读书笔记——Promise
  • Android单元测试 - 几个重要问题
  • axios请求、和返回数据拦截,统一请求报错提示_012
  • CSS3 变换
  • iOS 颜色设置看我就够了
  • Javascript编码规范
  • spring boot 整合mybatis 无法输出sql的问题
  • spring boot下thymeleaf全局静态变量配置
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 一道闭包题引发的思考
  • Spring Batch JSON 支持
  • 宾利慕尚创始人典藏版国内首秀,2025年前实现全系车型电动化 | 2019上海车展 ...
  • #Linux杂记--将Python3的源码编译为.so文件方法与Linux环境下的交叉编译方法
  • #宝哥教你#查看jquery绑定的事件函数
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第5节(封闭类和Final方法)
  • (done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW
  • (NSDate) 时间 (time )比较
  • (附源码)springboot宠物管理系统 毕业设计 121654
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (力扣题库)跳跃游戏II(c++)
  • (一)Linux+Windows下安装ffmpeg
  • (一)SpringBoot3---尚硅谷总结
  • (转)大型网站架构演变和知识体系
  • (轉貼) 資訊相關科系畢業的學生,未來會是什麼樣子?(Misc)
  • .Net - 类的介绍
  • .Net Core和.Net Standard直观理解
  • .NET Entity FrameWork 总结 ,在项目中用处个人感觉不大。适合初级用用,不涉及到与数据库通信。
  • .net(C#)中String.Format如何使用
  • .net中的Queue和Stack
  • .NET中使用Protobuffer 实现序列化和反序列化
  • @EventListener注解使用说明
  • [<MySQL优化总结>]
  • [2016.7.test1] T2 偷天换日 [codevs 1163 访问艺术馆(类似)]
  • [Android]Android开发入门之HelloWorld
  • [C]编译和预处理详解
  • [ccc3.0][数字钥匙] UWB配置和使用(二)
  • [ffmpeg] av_opt_set 解析
  • [GXYCTF2019]BabySQli1
  • [iOS]GCD(一)
  • [iOS开发]事件处理与响应者链