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- ...
随机推荐
- 基于Python+协程+多进程的通用弱密码扫描器
听说不想扯淡的程序猿,不是一只好猿.所以今天来扯扯淡,不贴代码,只讲设计思想. 0x00 起 - 初始设计 我们的目标是设计一枚通用的弱密码扫描器,基本功能是针对不同类型的弱密码,可方便的扩展,比如添 ...
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
Description 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法,他们也可 ...
- s3c2440之cache
cache高速缓冲存储器注意与块设备页高速缓存进行区别,一个是硬件的实现一个是软件的实现,块设备页高速缓存. s3c2440/s3c2410里面主要有一个arm920t的核,但同时包含几个协处理器,协 ...
- 1509 -- Glass Beads POJ
题意:求一个字符串的最小表示的开始下标 就当模板题写了 把字符串重复一遍,再建后缀自动机,贪心的选最小字典序在上面走len步 因为走出来的一定是子串,长度又是len,所以一定是原来的字符串旋转得到的, ...
- 基于局部敏感哈希的协同过滤算法之simHash算法
搜集了快一个月的资料,虽然不完全懂,但还是先慢慢写着吧,说不定就有思路了呢. 开源的最大好处是会让作者对脏乱臭的代码有羞耻感. 当一个做推荐系统的部门开始重视[数据清理,数据标柱,效果评测,数据统计, ...
- PAT-乙级-1025. 反转链表 (25)
1025. 反转链表 (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一个常数K以及一个单链表L,请 ...
- HTML字符实体(Character Entities),转义字符串(Escape Sequence)
为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希 ...
- EOJ-1708//POJ3334
题意: 有一个连通器,由两个漏斗组成(关于漏斗的描述见描述). 现向漏斗中注入一定量的水,问最终水的绝对位置(即y轴坐标) 思路: 总体来说分为3种情况. 1.两个漏斗可能同时装有水. 2.只可能a漏 ...
- 李洪强iOS开发之图片拉伸技巧
纵观移动市场,一款移动app,要想长期在移动市场立足,最起码要包含以下几个要素:实用的功能.极强的用户体验.华丽简洁的外观.华丽外观的背后,少不了美工的辛苦设计,但如果开发人员不懂得怎么合理展示这些设 ...
- HeadFirst设计模式之单例模式
一. 1.The Singleton Pattern ensures a class has only one instance, and provides a global point of acc ...