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.pswp.cn/bicheng/72823.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/72823.shtml
英文地址,請注明出處:http://en.pswp.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…