2019独角兽企业重金招聘Python工程师标准>>>
特点: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_EVENT_MODULE类型) 的上下文配置create_conf() = ngx_event_core_create_conf(),因为不知道哪个模块将在配置中,需要给所有的这类模块(编译时已加载)分配内存空间
- 例如:遇见一级events指令,则调用它的指令解析函数:ngx_events_block()
-
检测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_MODULE | errlog | error_log |
NGX_CORE_MODULE | thread_pool | thread_pool |
NGX_CORE_MODULE | openssl | ssl_engine |
NGX_CORE_MODULE | http | http |
NGX_CORE_MODULE | ||
NGX_CORE_MODULE | google_perftools | google_perftools_profiles |
NGX_CORE_MODULE | stream | stream |
NGX_CORE_MODULE | core | daemon、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_MODULE | NULL | include |
- *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_CONF | http、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;
}
}