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- ...
随机推荐
- easy ui 表单提交添加遮罩,避免数据重复提交
如下图: //点击提交按钮保存数据 $('#btn_submit').click(function () { //增加遮罩层 $.messager.progress({ title: '温馨提示', ...
- 正则表达式通过Unicode属性匹配
原文链接:http://zochen.iteye.com/blog/690716 Unicode 编码并不只是为某个字符简单定义了一个编码,而且还将其进行了归类. \pP 其中的小写 p 是 prop ...
- redis 在windows 上的安装与使用
1.redis-windows 最近在做一个抢拍模块,由于过于平凡的insert与update I/O受不了,故只好把东西放内存里,等拍卖结束了,在写入磁盘. 至于为什么要用window呢? 因为服务 ...
- spoj 1436
用并查集看一下是否会围成一个环 若围成环直接输出NO 当然 当 m >= n 时必然会围成环直接输出NO #include <algorithm> #include < ...
- firefly笔记一之http模块
原地址:http://www.9miao.com/question-15-54380.html Firefly是免费开源的游戏服务器端框架,开发语言是python,基于twisted框架开发,作为一名 ...
- mvc+entity framework database first,生成的model每次更新一个表会更新所有的model
在使用Entity Framework 的Database frist或model first时,直接加attribute到modle类上是太现实也不合理的,因为model类是自动生成的,重新生成后会 ...
- [扫描线]POJ2932 Coneology
题意:有n个圆 依次给了半径和圆心坐标 保证输入的圆不相交(只有 相离 和 内含/外含 的情况) 问 有几个圆 不内含在其他圆中,并分别列出这几个圆的编号(1~n) (n的范围是[1, 4000 ...
- PHP简单语法
PHP简单语法 声明变量 $var_name="1"; $var_num=1; $var_bool=true; var_dump"函数可以将我们的变量的数据类型显示出来. ...
- ArcGIS学习记录—属性表的编辑与修改
原文地址: ArcGIS问题:属性表的编辑与修改 - Silent Dawn的日志 - 网易博客 http://gisman.blog.163.com/blog/static/344933882009 ...
- Armitage初始化
Kali2.0 Armitage初始化步骤如下 (1)点击页面的Armitage按钮 (2)提示Metasploit RPC server is not running,是否启动该服务,选择是 (3) ...