NGINX(五)模块
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(五)模块的更多相关文章
- Nginx学习笔记六Nginx的模块开发
1.Nginx配置文件主要组成:main(全局配置)这部分的指令将影响其他所有部分.server(虚拟主机配置)这部分指令主要用于指定虚拟主机域名,IP和端口.upstream(主要为反向代理,负载均 ...
- Nginx RTMP 模块 nginx-rtmp-module 指令详解
译序:截至 Jul 8th,2013 官方公布的最新 Nginx RTMP 模块 nginx-rtmp-module 指令详解.指令Corertmp语法:rtmp { ... }上下文:根描述:保存所 ...
- 基于Nginx dyups模块的站点动态上下线并实现简单服务治理
简介 今天主要讨论一下,对于分布式服务,站点如何平滑的上下线问题. 分布式服务 在分布式服务下,我们会用nginx做负载均衡, 业务站点访问某服务站点的时候, 统一走nginx, 然后nginx根据一 ...
- Nginx 切片模块、断点续传
熟悉 CDN 行业主流技术的朋友应该都比较清楚,虽然 Nginx 近几年发展的如日中天,但是基本上没有直接使用它自带的 proxy_cache 模块来做缓存的,原因有很多,例如下面几个: 不支持多盘 ...
- nginx事件模块分析(一)
nginx ngx_events_module模块分析 ngx_events_module模块是核心模块之一,它是其它所有事件模块的代理模块.nginx在启动时只与events模块打交道,而由even ...
- mac下Nginx+lua模块编译安装
Nginx的nb之处就不说了,lua也是一个小巧的脚本语言,由标准C编写而成,几乎可以运行在所有的平台上,也非常强大,其他特性请自行度娘.nginx_lua_module是由淘宝的工程师清无(王晓哲) ...
- nginx添加模块 (非覆盖安装)
nginx添加模块(非覆盖安装) 原已经安装好的nginx,现在需要添加一个未被编译安装的模块: 查看原来编译时都带了哪些参数# /usr/local/nginx/sbin/nginx -V ngin ...
- 一些好用的nginx第三方模块
一些好用的nginx第三方模块 转自;http://macken.iteye.com/blog/1963301 1.Development Kit https://github.com/simpl/ ...
- 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- ...
随机推荐
- SRM 616 ColorfulCoins
题意:给定一个从小到大的货币面值,每一个面额都是其前面面额的倍数(倍数大于等于2),每一种货币面值对应一种颜色,目前不清楚面值与颜色的对应关系.要求用最少的查询次数来确定面额与颜色的对应关系.(一次查 ...
- (转载)猫都能学会的Unity3D Shader入门指南(一)
原文地址 http://onevcat.com/2013/07/shader-tutorial-1/ 动机 自己使用Unity3D也有一段时间了,但是很多时候是流于表面,更多地是把这个引擎简单地用作脚 ...
- 在Hadoop分布式文件系统的索引和搜索
FROM:http://www.drdobbs.com/parallel/indexing-and-searching-on-a-hadoop-distr/226300241?pgno=3 在今天的信 ...
- java第五课:方法
方法交换位置的三个步骤:1.把第一个盒子里的东西拿出来,放到一边2.把第二个盒子里的东西放到第一个盒子里3.捡起刚刚放到一边的东西,放到第二个盒子里 值传递:实际参数将内部保存的值,复制给方法的参数. ...
- 如何安装Favicon
如何安装Favicon favicon.ico图像放在根目录下(也可以是其他目录)在页面源文件的<head></head>标签之间插入 <link rel="s ...
- ExtJS4.2学习(六)表格分页与通过后台脚本获得分页数据
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-12/175.html --------------- ...
- [转载]OpenFileDialog对话框Filter属性
首先说明一个示例,分析一下Filter属性的构成:“ Excel文件|*.xls ”,前面的“Excel文件”成为标签,是一个可读的字符串,可以自定定义,“|*.xls”是筛选器,表示筛选文件夹中后缀 ...
- Android支付接入(二):移动游戏基地
原地址:http://blog.csdn.net/simdanfeg/article/details/9011863 上篇博文跟大家一起走了一遍支付宝支付,今天我们来看看移动支付.众所周知目前付费通道 ...
- win7 64bit下最新Apahe2.4.18+php7.0.2+MySQL5.7.10配置
原文:win7 64bit下最新Apahe2.4.18+php7.0.2+MySQL5.7.10配置 一.说明 以前配置apache+php+mysql都是参考网上的,一般都没有什么问题.最近公司有个 ...
- CodeForces250B——Restoring IPv6(字符串处理)
Restoring IPv6 DescriptionAn IPv6-address is a 128-bit number. For convenience, this number is recor ...