当前位置: 首页 > news >正文

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 主要用于程序内索引,更加高效

相关文章:

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_modul…...

css错峰布局/瀑布流样式(类似于快手样式)

当样式一侧比较高的时候会自动换行&#xff0c;尽量保持高度大概一致&#xff0c; 例&#xff1a; 一侧元素为5&#xff0c;另一侧元素为6 当为5的一侧过于高的时候&#xff0c;可能会变为4/7分部dom节点 如果不需要这样的话删除样式 flex-flow:column wrap; 设置父级dom样…...

【并发编程】聊聊定时任务ScheduledThreadPool的实现原理和源码解析

ScheduledThreadPoolExecutor 是在线程池的基础上 拓展的定时功能的线程池&#xff0c;主要有四种方式&#xff0c;具体可以看代码&#xff0c; 这里主要描述下 scheduleAtFixedRate &#xff1a; 除了第一次执行的时间&#xff0c;后面任务执行的时间 为 time MAX(任务执行时…...

【虚拟化】Docker Desktop 架构简介

在阅读前您需要了解 docker 架构&#xff1a;Docker architecture WSL 技术&#xff1a;什么是 WSL 2 1.Hyper-V backend 我们知道&#xff0c;Docker Desktop 最开始的架构的后端是采用的 Hyper-V。 Docker daemon (dockerd) 运行在一个 Linux distro (LinuxKit build) 中&…...

DeepSeek 医疗大模型微调实战讨论版(第一部分)

DeepSeek医疗大模型微调实战指南第一部分 DeepSeek 作为一款具有独特优势的大模型,在医疗领域展现出了巨大的应用潜力。它采用了先进的混合专家架构(MoE),能够根据输入数据的特性选择性激活部分专家,避免了不必要的计算,极大地提高了计算效率和模型精度 。这种架构使得 …...

c++实现最大公因数和最小公倍数

最大公因数和最小公倍数的介绍 读这篇文章&#xff0c;请你先对最大公因数以及最小公倍数进行了解&#xff1a; 最大公因数&#xff08;英文名&#xff1a;gcd&#xff09; 定义&#xff1a;最大公因数&#xff0c;也称最大公约数&#xff0c;指两个或多个整数共有约数&…...

知识库Dify和cherry无法解析影印pdf word解决方案

近期收到大量读者反馈&#xff1a;上传pdf/图文PDF到Dify、Cherry Studio等知识库时&#xff0c;普遍存在格式错乱、图片丢失、表格失效三大痛点。 在试用的几款知识库中除了ragflow具备图片解析的能力外&#xff0c;其他的都只能解析文本。 如果想要解析扫描件&#xff0c…...

【记录一下学习】Embedding 与向量数据库

一、向量数据库 向量数据库&#xff08;Vector Database&#xff09;&#xff0c;也叫矢量数据库&#xff0c;主要用来存储和处理向量数据。 在数学中&#xff0c;向量是有大小和方向的量&#xff0c;可以使用带箭头的线段表示&#xff0c;箭头指向即为向量的方向&#xff0c…...

【第21节】C++设计模式(行为模式)-Chain of Responsibility(责任链)模式

一、问题背景 在 VC/MFC 开发中&#xff0c;消息处理机制是核心部分之一。VC 是基于消息和事件驱动的框架&#xff0c;消息的处理流程通常是通过链式传递的方式进行的。例如&#xff0c;一个 WM_COMMAND 消息的处理流程可能如下&#xff1a; &#xff08;1&#xff09;MDI 主窗…...

createrepo centos通过nginx搭建本地源

yum update 先安装一个nginx。 安装Nginx yum install gcc gcc-c pcre pcre-devel openssl openssl-devel libtool zlib zlib-devel -y cd /usr/local/src wget http://nginx.org/download/nginx-1.22.0.tar.gz tar -zxvf nginx-1.22.0.tar.gz cd nginx-1.22.0 ./configu…...

在 Docker 中搭建GBase 8s主备集群环境

本文介绍了如何在同一台机器上使用 Docker 容器搭建GBase 8s主备集群环境。 拉取镜像 拉取GBase 8s的最新镜像 docker pull liaosnet/gbase8s或者docker pull liaosnet/gbase8s:v8.8_3513x25_csdk_x64注&#xff1a;在tag为v8.8_3513x25_csdk_x64及之后的版本中&#xff0c;…...

【MySQL-数据类型】数据类型分类+数值类型+文本、二进制类型+String类型

一、数据类型分类 二、数值类型 1.bit类型 测试环境ubuntu 基本语法&#xff1a; bit[(M)]&#xff1a;位字段类型&#xff0c;M表示每个值的位数&#xff0c;范围从1&#xff5e;64&#xff1b;如果M被忽略&#xff0c;默认为1举例&#xff1a; create table testBit(id i…...

小谈java内存马

基础知识 &#xff08;代码功底不好&#xff0c;就找ai优化了一下&#xff09; Java内存马是一种利用Java虚拟机&#xff08;JVM&#xff09;动态特性&#xff08;如类加载机制、反射技术等&#xff09;在内存中注入恶意代码的攻击手段。它不需要在磁盘上写入文件&#xff0c…...

简单的二元语言模型bigram实现

内容总结归纳自视频&#xff1a;【珍藏】从头开始用代码构建GPT - 大神Andrej Karpathy 的“神经网络从Zero到Hero 系列”之七_哔哩哔哩_bilibili 项目&#xff1a;https://github.com/karpathy/ng-video-lecture Bigram模型是基于当前Token预测下一个Token的模型。例如&#x…...

【清华大学】实用DeepSeek赋能家庭教育 56页PDF文档完整版

清华大学-56页&#xff1a;实用DeepSeek赋能家庭教育.pdf https://pan.baidu.com/s/1BUweVDeG2M8-t0QaIs3LHQ?pwd1234 提取码: 1234 或 https://pan.quark.cn/s/8a9473493bb0 《实用DeepSeek赋能家庭教育》基于清华大学研究成果&#xff0c;系统阐述了DeepSeek人工智能技…...

黑洞如何阻止光子逃逸

虽然涉及广义相对论&#xff0c;但广义相对论说的是大质量物体对周围空间的影响&#xff0c;而不是说周围空间和空间中的光子之间的关系。也就是说&#xff0c;若讨论光子逃逸问题&#xff0c;则不必限定于大质量的前提&#xff0c;也就是说&#xff0c;若质量周围被扭曲的空间…...

1.4 单元测试与热部署

本次实战实现Spring Boot的单元测试与热部署功能。单元测试方面&#xff0c;通过JUnit和Mockito等工具&#xff0c;结合SpringBootTest注解&#xff0c;可以模拟真实环境对应用组件进行独立测试&#xff0c;验证逻辑正确性&#xff0c;提升代码质量。具体演示了HelloWorld01和H…...

window系统中的start命令详解

start 是 Windows 系统中用于启动新进程或打开新窗口来运行指定程序或命令的命令。以下是对 start 命令参数的详细解释&#xff1a; 基本语法 start ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENO…...

AI编程工具节选

1、文心快码 百度基于文心大模型推出的一款智能编码助手&#xff0c; 官网地址&#xff1a;文心快码(Baidu Comate)更懂你的智能代码助手 2、通义灵码 阿里云出品的一款基于通义大模型的智能编码辅助工具&#xff0c; 官网地址&#xff1a;通义灵码_你的智能编码助手-阿里云 …...

正则表达式,idea,插件anyrule

​​​​package lx;import java.util.regex.Pattern;public class lxx {public static void main(String[] args) {//正则表达式//写一个电话号码的正则表达式String regex "1[3-9]\\d{9}";//第一个数字是1&#xff0c;第二个数字是3-9&#xff0c;后面跟着9个数字…...

《计算机网络》再学习

1.TCP/IP与OSI模型1&#xff09;TCP/IP模型应用层&#xff1a;为程序提供网络服务。协议&#xff1a;HTTP&#xff0c;DNS与FTP等传输层&#xff1a;提供端到端的通信服务&#xff0c;确保数据的可靠传输。协议&#xff1a;TCP与UDP网络层&#xff1a;负责数据包的路由与转发。…...

OpenClaw对接nanobot镜像:低成本实现本地AI助手自动化任务

OpenClaw对接nanobot镜像&#xff1a;低成本实现本地AI助手自动化任务 1. 为什么选择OpenClawnanobot组合 去年夏天&#xff0c;当我第一次尝试用AI自动化处理日常工作时&#xff0c;发现大多数方案要么需要昂贵的云服务API调用&#xff0c;要么对硬件要求极高。直到遇到Open…...

在Windows和RV1126上部署ONNX肺部分割模型:一份OpenCV DNN与RKNN的完整对比实践

跨平台肺部分割模型部署实战&#xff1a;OpenCV DNN与RKNN技术选型指南 当医疗影像分析遇上边缘计算&#xff0c;开发者们常常面临一个关键抉择&#xff1a;如何在保证精度的前提下&#xff0c;将训练好的深度学习模型高效部署到不同计算平台&#xff1f;本文将以肺部分割模型为…...

YOLOv8自定义检测头踩坑记:手把手教你修复‘NotImplementedError: new_detect task‘错误

YOLOv8自定义检测头实战&#xff1a;从报错到修复的深度解析 当你在YOLOv8框架中尝试添加一个名为new_detect的自定义检测头时&#xff0c;突然遇到NotImplementedError: new_detect task错误&#xff0c;这可能会让你感到困惑。本文将带你深入理解YOLOv8的任务调度机制&#x…...

实战复盘:我是如何用Turbo Intruder的race.py脚本,5分钟挖到一个高并发订单漏洞的

高并发漏洞狩猎实录&#xff1a;从Turbo Intruder脚本调优到电商系统攻防实战 去年在一次众测项目中&#xff0c;我偶然发现某电商平台的积分兑换系统存在并发处理缺陷。这个漏洞最终被评级为高危&#xff0c;而整个挖掘过程只用了不到5分钟——关键就在于对Turbo Intruder的ra…...

从随机采样到精准决策:蒙特卡罗方法在复杂系统建模中的实践

1. 蒙特卡罗方法&#xff1a;用随机性破解复杂世界的密码 想象你是一位古代数学家&#xff0c;手里只有一把沙子和一块画着方格的石板。现在要计算一个不规则形状的湖泊面积&#xff0c;你会怎么做&#xff1f;最原始的方法可能是把沙子均匀撒在石板上&#xff0c;然后数出落在…...

ApiPost实战指南:从接口创建到自动化测试的全流程解析

1. 从零开始创建你的第一个API接口 作为一个常年和API打交道的开发者&#xff0c;我深知新手第一次接触接口工具时的迷茫。ApiPost作为一款国产的API开发工具&#xff0c;用起来确实比Postman更顺手&#xff0c;特别是对中文用户特别友好。下面我就带你一步步创建第一个接口&am…...

零基础一键配置黑苹果:OpCore-Simplify智能工具让复杂变简单

零基础一键配置黑苹果&#xff1a;OpCore-Simplify智能工具让复杂变简单 【免费下载链接】OpCore-Simplify A tool designed to simplify the creation of OpenCore EFI 项目地址: https://gitcode.com/GitHub_Trending/op/OpCore-Simplify 还在为黑苹果配置时面对满屏代…...

腾讯游戏卡顿终极解决方案:ACE-Guard资源限制器完整指南

腾讯游戏卡顿终极解决方案&#xff1a;ACE-Guard资源限制器完整指南 【免费下载链接】sguard_limit 限制ACE-Guard Client EXE占用系统资源&#xff0c;支持各种腾讯游戏 项目地址: https://gitcode.com/gh_mirrors/sg/sguard_limit 你是否在玩《地下城与勇士》、《英雄…...

部署开源的Minecraft服务器智能运维管理系统 Minecraft-Rcon-Manage 自存简易教程

项目地址&#xff1a;Minecraft-Rcon-Manage 前言 笔者最近寻找一款能实现Minecraft服务器RCON远程访问的工具&#xff0c;找到了这个目前正在持续更新、功能丰富的开源项目Minecraft-Rcon-Manage&#xff0c;但实际部署过程中发现作者提供的教程博客无法正常访问&#xff0c…...