Ubuntu 下 nginx-1.24.0 源码分析 - ngx_modules

定义在 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_v2_module;
extern ngx_module_t  ngx_http_static_module;
extern ngx_module_t  ngx_http_gzip_static_module;
extern ngx_module_t  ngx_http_autoindex_module;
extern ngx_module_t  ngx_http_index_module;
extern ngx_module_t  ngx_http_mirror_module;
extern ngx_module_t  ngx_http_try_files_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_grpc_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_random_module;
extern ngx_module_t  ngx_http_upstream_keepalive_module;
extern ngx_module_t  ngx_http_upstream_zone_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_v2_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_copy_filter_module;
extern ngx_module_t  ngx_http_range_body_filter_module;
extern ngx_module_t  ngx_http_not_modified_filter_module;
extern ngx_module_t  ngx_stream_module;
extern ngx_module_t  ngx_stream_core_module;
extern ngx_module_t  ngx_stream_log_module;
extern ngx_module_t  ngx_stream_proxy_module;
extern ngx_module_t  ngx_stream_upstream_module;
extern ngx_module_t  ngx_stream_write_filter_module;
extern ngx_module_t  ngx_stream_ssl_module;
extern ngx_module_t  ngx_stream_limit_conn_module;
extern ngx_module_t  ngx_stream_access_module;
extern ngx_module_t  ngx_stream_geo_module;
extern ngx_module_t  ngx_stream_map_module;
extern ngx_module_t  ngx_stream_split_clients_module;
extern ngx_module_t  ngx_stream_return_module;
extern ngx_module_t  ngx_stream_set_module;
extern ngx_module_t  ngx_stream_upstream_hash_module;
extern ngx_module_t  ngx_stream_upstream_least_conn_module;
extern ngx_module_t  ngx_stream_upstream_random_module;
extern ngx_module_t  ngx_stream_upstream_zone_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_v2_module,&ngx_http_static_module,&ngx_http_gzip_static_module,&ngx_http_autoindex_module,&ngx_http_index_module,&ngx_http_mirror_module,&ngx_http_try_files_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_grpc_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_random_module,&ngx_http_upstream_keepalive_module,&ngx_http_upstream_zone_module,&ngx_http_write_filter_module,&ngx_http_header_filter_module,&ngx_http_chunked_filter_module,&ngx_http_v2_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,&ngx_stream_module,&ngx_stream_core_module,&ngx_stream_log_module,&ngx_stream_proxy_module,&ngx_stream_upstream_module,&ngx_stream_write_filter_module,&ngx_stream_ssl_module,&ngx_stream_limit_conn_module,&ngx_stream_access_module,&ngx_stream_geo_module,&ngx_stream_map_module,&ngx_stream_split_clients_module,&ngx_stream_return_module,&ngx_stream_set_module,&ngx_stream_upstream_hash_module,&ngx_stream_upstream_least_conn_module,&ngx_stream_upstream_random_module,&ngx_stream_upstream_zone_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_v2_module","ngx_http_static_module","ngx_http_gzip_static_module","ngx_http_autoindex_module","ngx_http_index_module","ngx_http_mirror_module","ngx_http_try_files_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_grpc_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_random_module","ngx_http_upstream_keepalive_module","ngx_http_upstream_zone_module","ngx_http_write_filter_module","ngx_http_header_filter_module","ngx_http_chunked_filter_module","ngx_http_v2_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","ngx_stream_module","ngx_stream_core_module","ngx_stream_log_module","ngx_stream_proxy_module","ngx_stream_upstream_module","ngx_stream_write_filter_module","ngx_stream_ssl_module","ngx_stream_limit_conn_module","ngx_stream_access_module","ngx_stream_geo_module","ngx_stream_map_module","ngx_stream_split_clients_module","ngx_stream_return_module","ngx_stream_set_module","ngx_stream_upstream_hash_module","ngx_stream_upstream_least_conn_module","ngx_stream_upstream_random_module","ngx_stream_upstream_zone_module",NULL
};

ngx_modules 是一个全局数组,类型为 ngx_module_t *[],它的作用是存储 Nginx 中所有模块的指针。

Nginx 是一个高度模块化的 Web 服务器,无论是核心功能(如事件处理、HTTP 处理)还是扩展功能(如反向代理、负载均衡、SSL 支持),都是通过模块实现的。

ngx_modules 提供了一个集中式的注册表,Nginx 在启动时通过遍历这个数组来初始化和配置所有模块。

具体来说:

  1. 模块注册:每个模块(无论是内置模块还是第三方模块)在编译时都会生成一个 ngx_module_t 结构体,描述该模块的元信息(如名称、版本、命令、钩子函数等),而 ngx_modules 数组则将这些模块的指针集中起来。

  2. 动态加载的基础:通过 ngx_modules,Nginx 可以在运行时动态决定哪些模块需要被加载和执行,这为模块的灵活性和可扩展性奠定了基础。

  3. 初始化顺序控制ngx_modules 数组中的顺序通常由编译时的配置决定(例如通过 ./configure 指定),Nginx 会按照这个顺序依次初始化模块,确保依赖关系正确处理。

ngx_modules 是自动生成的代码,这个文件是在编译过程中由配置脚本根据用户的选择生成的 


ngx_module_t 定义在 src/core/ngx_core.h

typedef struct ngx_module_s          ngx_module_t;

ngx_module_s 定义在 src/core/ngx_module.h

struct ngx_module_s {ngx_uint_t            ctx_index;ngx_uint_t            index;char                 *name;ngx_uint_t            spare0;ngx_uint_t            spare1;ngx_uint_t            version;const char           *signature;void                 *ctx;ngx_command_t        *commands;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;
};

name 字段保存的是模块的名称,是每个模块的唯一标识符

index 是每个模块的唯一标识符,与 name 提供字符串标识不同,index 提供了一个整数形式的标识符,便于快速索引和引用

name 主要用于日志和配置文件,便于人的阅读理解,index 主要用于程序内索引,更加高效

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/72823.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

深度学习代码解读——自用

代码来自&#xff1a;GitHub - ChuHan89/WSSS-Tissue 借助了一些人工智能 2_generate_PM.py 功能总结 该代码用于 生成弱监督语义分割&#xff08;WSSS&#xff09;所需的伪掩码&#xff08;Pseudo-Masks&#xff09;&#xff0c;是 Stage2 训练的前置步骤。其核心流程为&a…

Java基础面试题全集

1. Java语言基础 1.1 Java是什么&#xff1f; • Java是一种广泛使用的编程语言&#xff0c;最初由Sun Microsystems&#xff08;现为Oracle公司的一部分&#xff09;于1995年发布。它是一种面向对象的、基于类的、通用型的编程语言&#xff0c;旨在让应用程序“编写一次&…

Selenium遇到Exception自动截图

# 随手小记 场景&#xff1a;测试百度&#xff1a; 点击新闻&#xff0c;跳转到新的窗口&#xff0c;找到输入框&#xff0c;输入“hello,world" 等到输入框的内容是hello,world, 这里有个错误&#xff0c;少了一个] 后来就实现了错误截图的功能&#xff0c;可以参考 …

【神经网络】python实现神经网络(一)——数据集获取

一.概述 在文章【机器学习】一个例子带你了解神经网络是什么中&#xff0c;我们大致了解神经网络的正向信息传导、反向传导以及学习过程的大致流程&#xff0c;现在我们正式开始进行代码的实现&#xff0c;首先我们来实现第一步的运算过程模拟讲解&#xff1a;正向传导。本次代…

Sentinel 笔记

Sentinel 笔记 1 介绍 Sentinel 是阿里开源的分布式系统流量防卫组件&#xff0c;专注于 流量控制、熔断降级、系统保护。 官网&#xff1a;https://sentinelguard.io/zh-cn/index.html wiki&#xff1a;https://github.com/alibaba/Sentinel/wiki 对比同类产品&#xff1…

manus本地部署方法研究测试

Manus本地部署方法&#xff0c;Manus邀请码实在太难搞了&#xff0c;昨晚看到有一个团队&#xff0c;5个人3个小时&#xff0c;一个完全免费、无需排队等待的OpenManus就做好了。 由于也是新手&#xff0c;找了好几轮&#xff0c;实在是没有找到合适的部署方法&#xff0c;自己…

FreeRTOS第15篇:FreeRTOS链表实现细节03_List_t与ListItem_t的奥秘

文/指尖动听知识库-星愿 文章为付费内容,商业行为,禁止私自转载及抄袭,违者必究!!! 文章专栏:深入FreeRTOS内核:从原理到实战的嵌入式开发指南 1 FreeRTOS列表的核心数据结构 FreeRTOS的列表实现由两个关键结构体组成:List_t(列表)和ListItem_t(列表项)。它们共同…

gzip压缩

什么是Gzip 前端优化&#xff1a;开启Gzip压缩_前端开启gzip压缩-CSDN博客 Gzip是一种文件压缩算法&#xff0c;减少文件大小&#xff0c;节省带宽从而提减少网络传输时间&#xff0c;网站会更快地加载。 如何判断是否开启&#xff1a; 请求头&#xff1a;服务端会通过客户…

机器学习在地图制图学中的应用

原文链接&#xff1a;https://www.tandfonline.com/doi/full/10.1080/15230406.2023.2295948#abstract CSDN/2025/Machine learning in cartography.pdf at main keykeywu2048/CSDN GitHub 核心内容 本文是《制图学与地理信息科学》特刊的扩展评论&#xff0c;系统探讨了机…

智慧消防新篇章:4G液位/压力传感器,筑牢安全防线!

火灾无情&#xff0c;防患未“燃”&#xff01;在智慧消防时代&#xff0c;如何实现消防水系统的实时监测、预警&#xff0c;保障人民生命财产安全&#xff1f;山东一二三物联网深耕物联网领域&#xff0c;自主研发4G液位、4G压力智能传感器&#xff0c;为智慧消防水位、水压无…

set、LinkedHashSet和TreeSet的区别、Map接口常见方法、Collections 工具类使用

DAY7.2 Java核心基础 想学习Collection、list、ArrayList、Set、HashSet部分的小伙伴可以转到 7.1集合框架、Collection、list、ArrayList、Set、HashSet和LinkedHashSet、判断两个对象是否相等文章查看 set集合 在set集合中&#xff0c;处理LinkedHashSet是有序的&#xf…

windows:curl: (60) schannel: SEC_E_UNTRUSTED_ROOT (0x80090325)

目录 1. git update-git-for-windows 报错2. 解决方案2.1. 更新 CA 证书库2.2. 使用 SSH 连接&#xff08;推荐&#xff09;2.3 禁用 SSL 验证&#xff08;不推荐&#xff09; 1. git update-git-for-windows 报错 LenovoLAPTOP-EQKBL89E MINGW64 /d/YHProjects/omni-channel-…

《深度剖析架构蒸馏与逻辑蒸馏:探寻知识迁移的差异化路径》

在人工智能模型优化的前沿领域&#xff0c;架构蒸馏与逻辑蒸馏作为知识蒸馏的关键分支&#xff0c;正引领着模型小型化与高效化的变革浪潮。随着深度学习模型规模与复杂度的不断攀升&#xff0c;如何在资源受限的情况下&#xff0c;实现模型性能的最大化&#xff0c;成为了学术…

先序二叉树的线索化,并找指定结点的先序后继

#include<stdio.h> #include<stdlib.h> #define elemType char //线索二叉树结点 typedef struct ThreadNode{ elemType data; struct ThreadNode *lchild,*rchild; int ltag,rtag;//用来判断一个结点是否有线索 }ThreadNode,*ThreadTree; //全局变量…

蚂蚁集团转正实习大模型算法岗内推

1.负责以大模型为代表的A转术能力的建设和优化&#xff0c;打造业界领先的A(技术系统&#xff0c;主要职责包括A系统结构设计、RAG 系统开发、大模型凯练数据构建、大模型能力评测、大模型准理效果和效率优化等 2.紧密跟踪、探索大模型方向前沿技术&#xff0c;依托丰富目体系化…

未授权漏洞大赏

ActiveMQ未授权访问漏洞 漏洞描述 Apache ActiveMQ是美国阿帕奇&#xff08;Apache&#xff09;软件基金会所研发的一套开源的消息中间件&#xff0c;它支持Java消息服务、集群、Spring Framework等。 Apache ActiveMQ管理控制台的默认管理用户名和密码分别为admin和admin&am…

Python包结构与 `__init__.py` 详解

1. 什么是 __init__.py&#xff1f; __init__.py 是Python包的标识文件&#xff0c;它告诉Python解释器这个目录应该被视为一个包&#xff08;Package&#xff09;。这个文件可以为空&#xff0c;也可以包含初始化代码。 1.1 基本作用 包的标识 将普通目录转换为Python包允许…

Web前端开发——HTML基础下

HTML语法 一表格1.基本格式2.美化表格合并居中属性 二表单1.input2.select3.textarea4.button5.date6.color7.checkbox8.radio9.range10.number 一表格 1.基本格式 HTML表格由<table>标签定义 其中行由<tr>标签定义&#xff0c;单元格由<td>定义。我们先来…

小程序事件系统 —— 33 事件传参 - data-*自定义数据

事件传参&#xff1a;在触发事件时&#xff0c;将一些数据作为参数传递给事件处理函数的过程&#xff0c;就是事件传参&#xff1b; 在微信小程序中&#xff0c;我们经常会在组件上添加一些自定义数据&#xff0c;然后在事件处理函数中获取这些自定义数据&#xff0c;从而完成…

安卓设备root检测与隐藏手段

安卓设备root检测与隐藏手段 引言 安卓设备的root权限为用户提供了深度的系统控制能力&#xff0c;但也可能带来安全风险。因此&#xff0c;许多应用&#xff08;如银行软件、游戏和流媒体平台&#xff09;会主动检测设备是否被root&#xff0c;并限制其功能。这种对抗催生了ro…