nginx模块分为以下几类:

NGX_CORE_MODULE  //核心模块
NGX_HTTP_MODULE //HTTP处理模块
NGX_EVENT_MODULE //事件处理模块
NGX_MAIL_MODULE //邮件处理模块

涉及数据结构

/*模块可解析的配置命令*/
struct ngx_command_s {
/*命令名称如http, server, listen等*/
ngx_str_t name ;
/*命令类型如:NGX_HTTP_MAIN_CONF,NGX_HTTP_SRV_CONF,这里还要指定参数可以接受的参数个数或类型如NGX_CONF_TAKE1代表可接受一个参数,
*假如我们配置:NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1表示该命令既可以出现在main_conf中也可以出现在srv_conf中,并且必须接受一个参数
*/
ngx_uint_t type ;
/*解析命令的回调函数指针,这里可以递归进行解析,也可以只进行简单的赋值*/
char *(*set)( ngx_conf_t *cf , ngx_command_t *cmd, void *conf);
/*表示模块自定义的配置所在位置*/
ngx_uint_t conf ;
/*表示当前命令值在配置中偏移量*/
ngx_uint_t offset ;
void *post;
}; /*
*核心模块定义数据结构
*/
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; /*
*模块定义数据结构
*/
struct ngx_module_s {
/*模块在外层配置上下文中索引,假如是NGX_HTTP_MODULE,则代表自定义配置在ngx_http_ctx_t中main_conf,srv_conf,loc_conf配置的索引*/
ngx_uint_t ctx_index ;
/*所有模块中此模块的索引,即全局ngx_modules数组中的位置*/
ngx_uint_t index ; ngx_uint_t spare0 ;
ngx_uint_t spare1 ;
ngx_uint_t spare2 ;
ngx_uint_t spare3 ; ngx_uint_t version ;
/*模块上下文指针,主要包括一些模块自定义的回调函数指针或数据,假如是NGX_HTTP_MODULE,则此处则是ngx_http_module_t指针*/
void *ctx;
/*模块定义可以解析的配置命令列表*/
ngx_command_t *commands;
/*模块类型NGX_HTTP_MODULE,NGX_MAIL_MODULE等*/
ngx_uint_t type ; /*主进程初始化时回调函数指针*/
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 ;
};

示例说明

nginx模块是执行configure时生成模块列表,保存在ngx_modules.c中,以下是我本机生成的模块列表

ngx_module_t *ngx_modules [] = {
&ngx_core_module ,
&ngx_errlog_module ,
&ngx_conf_module ,
&ngx_events_module ,
&ngx_event_core_module ,
&ngx_epoll_module ,
&ngx_regex_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_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_ip_hash_module ,
&ngx_http_upstream_least_conn_module ,
&ngx_http_upstream_keepalive_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_copy_filter_module ,
&ngx_http_range_body_filter_module ,
&ngx_http_not_modified_filter_module ,
NULL
};

其中ngx_core_module,ngx_http_module,ngx_errlog_module,ngx_regex_module,ngx_events_module,ngx_mail_module属于NGX_CORE_MODULE类型,nginx启动时首先加载所有的NGX_CORE_MODULE模块,其他模块均有NGX_CORE_MODULE模块加载,例如启动时加载ngx_http_module模块,此模块会依次加载所有的NGX_HTTP_MODULE类型模块,包括加载配置和进行初始化工作。

NGINX(五)模块的更多相关文章

  1. Nginx学习笔记六Nginx的模块开发

    1.Nginx配置文件主要组成:main(全局配置)这部分的指令将影响其他所有部分.server(虚拟主机配置)这部分指令主要用于指定虚拟主机域名,IP和端口.upstream(主要为反向代理,负载均 ...

  2. Nginx RTMP 模块 nginx-rtmp-module 指令详解

    译序:截至 Jul 8th,2013 官方公布的最新 Nginx RTMP 模块 nginx-rtmp-module 指令详解.指令Corertmp语法:rtmp { ... }上下文:根描述:保存所 ...

  3. 基于Nginx dyups模块的站点动态上下线并实现简单服务治理

    简介 今天主要讨论一下,对于分布式服务,站点如何平滑的上下线问题. 分布式服务 在分布式服务下,我们会用nginx做负载均衡, 业务站点访问某服务站点的时候, 统一走nginx, 然后nginx根据一 ...

  4. Nginx 切片模块、断点续传

    熟悉 CDN 行业主流技术的朋友应该都比较清楚,虽然 Nginx 近几年发展的如日中天,但是基本上没有直接使用它自带的 proxy_cache 模块来做缓存的,原因有很多,例如下面几个: 不支持多盘 ...

  5. nginx事件模块分析(一)

    nginx ngx_events_module模块分析 ngx_events_module模块是核心模块之一,它是其它所有事件模块的代理模块.nginx在启动时只与events模块打交道,而由even ...

  6. mac下Nginx+lua模块编译安装

    Nginx的nb之处就不说了,lua也是一个小巧的脚本语言,由标准C编写而成,几乎可以运行在所有的平台上,也非常强大,其他特性请自行度娘.nginx_lua_module是由淘宝的工程师清无(王晓哲) ...

  7. nginx添加模块 (非覆盖安装)

    nginx添加模块(非覆盖安装) 原已经安装好的nginx,现在需要添加一个未被编译安装的模块: 查看原来编译时都带了哪些参数# /usr/local/nginx/sbin/nginx -V ngin ...

  8. 一些好用的nginx第三方模块

    一些好用的nginx第三方模块 转自;http://macken.iteye.com/blog/1963301  1.Development Kit https://github.com/simpl/ ...

  9. nginx自定义模块编写-实时统计模块--转载

    原文:http://www.vimer.cn/2012/05/nginx%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A8%A1%E5%9D%97%E7%BC%96%E5%86%99- ...

随机推荐

  1. Unity3d + UGUI 的多分辨率适配

    原文地址:http://blog.csdn.net/dingkun520wy/article/details/49471789 1.Canvas的属性配置 2.Canvas Scaler的属性配置 3 ...

  2. jmeter测试本地myeclips调试状态下的tomcat程序死锁

    在myeclipse调试状态下的tomcat程序,用jmeter测试,居然发生死锁,调试两天无果,直接运行tomcat而不通过myeclipse,无死锁,真是又好气又好笑..

  3. VPN销售管理系统一键安装包

    wget http://d.zmrbk.com/vpn/zmrvpn.sh;chmod +x zmrvph.sh;sh zmrvpn.sh 2>&1 | tee zmrbk.com.lo ...

  4. linux 安装firefox

    从火狐官网下载的firefox-9.0.1.tar.bz2解压后,进入firefox文件夹,执行./firefox会提示缺少库,故采用yum安装Firefox9.1.切换到root用户 su - 2. ...

  5. 内存泄露 memory leak 的原因

    #include <iostream> using namespace std; void foo() { MyClass *x; x = new MyClass(); //指向的丢失了 ...

  6. 【C++基础】内存操作 getMemory改错

    内存操作的考察点:①指针 ②变量生存期及作用范围 ③动态内存申请和释放 笔试题************************************************************* ...

  7. python List&Set&Dict交集、并集、差集

    1.python List交集.并集.差集 1). 获取两个list 的交集#方法一: a=[2,3,4,5] b=[2,5,8] tmp = [val for val in a if val in  ...

  8. 使用IDEA自带maven建java项目时报错。

    今天用IDEA建立maven项目时报错: [INFO] Scanning for projects... [INFO] Searching repository for plugin with pre ...

  9. http://www.cnblogs.com/doit8791/p/4093808.html

    http://www.cnblogs.com/doit8791/p/4093808.html

  10. TCP长连接与短连接的区别

    http://www.cnblogs.com/liuyong/archive/2011/07/01/2095487.html 1. TCP连接 当网络通信时采用TCP协议时,在真正的读写操作之前,se ...