elloWorld 是一个典型的 location 模块.什么是 location 模块?在 Nginx 中,根据作用域,有 main 模块.server 模块.location 模块. 1 模块定义 在 HelloWorld 模块中有一个 ngx_http_hello_world_module 变量,用于定义模块.它是 ngx_module_t 类型.ngx_module_t 是 ngx_module_s 的别名,其定义如下: struct ngx_module_s { ngx_uint_t…
1 学习 Nginx 模块开发需要有哪些准备? 需要的预备知识不多,有如下几点: 有过一些 C 语言的编程经历: 知道 Nginx 是干嘛的,并有过编写或改写 Nginx 的配置文件的经历. OK,就这两点就够了 :) 好了,那就开始吧~ 2 我们的 HelloWorld 的目标是什么? 我们的目标,就是你在浏览器里输入http://localhost/hello_world时,显示: hello world 当然,为了能够更加自定义一些,我们尝试在hello world后面再显示一个字符串,比…
背景介绍 nginx历史 使用简介 nginx特点介绍 nginx平台初探(100%) 初探nginx架构(100%) nginx基础概念(100%) connection request 基本数据结构(99%) ngx_str_t(100%) ngx_pool_t(100%) ngx_array_t(100%) ngx_hash_t(100%) ngx_hash_wildcard_t(100%) ngx_hash_combined_t(100%) ngx_hash_keys_arrays_t(…
与HTTP处理模块不同.HTTP过滤模块的工作是对发送给用户的HTTP响应做一些加工. server返回的一个响应能够被随意多个HTTP过滤模块以流水线的方式依次处理.HTTP响应分为头部和包体,ngx_http_send_header和ngx_http_output_filter函数分别负责发送头部和包体.它们会依次调用各个过滤模块对待发送的响应进行处理. HTTP过滤模块能够单独处理响应的头部或者包体或同一时候处理二者.处理头部和包体的方法原型分别例如以下,它们在HTTP框架模块ngx_ht…
在 Nginx 的自动脚本中,auto/cc目录下的所有脚本都是用于编译器相关配置使用的.Nginx的出色跨平台性(Linux.Darwin.Solaris.Win32 等)就有这些脚本的贡献.该目录下包含如下脚本: 目录 conf:主脚本,配置编译器的基本属性,并根据系统的编译器环境引用不同的脚本. name:与编译器名称相关的处理逻辑在该脚本中. gcc:GNU C 编译器的 Specified 配置. sunc:Sun C 编译器的 Specified 配置. acc:HP ANSI C+…
还记得我们定义过一个结构体如下吗? typedef struct { ngx_str_t output_words; } ngx_http_hello_world_loc_conf_t; 它就是 HelloWorld 的 location 组件配置,其中有一个字符串成员 output_words. 1 create location 用于 ngx_http_hello_world_module_ctx 中的 location 创建函数: static void* ngx_http_hello_w…
1 Background ngx_http_stub_status_module 是一个 Nginx 的内置 HTTP 模块,该模块可以提供 Nginx 的状态信息.默认情况下这个模块是不被编译进来的,所以在编译 Nginx 时要指定加载该模块: --with-http_stub_status_module 当然了,如果你是重新编译,仅仅-s reload是不够的,可能需要用到平滑升级:<高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx>. 为什么拿它做例子?因为它也…
1 命名规则 1.1 基本变量 基本变量有三个: ngx_module_t 类型的 ngx_http_foo_bar_module: ngx_command_t 类型的数组 ngx_http_foo_bar_commands: ngx_http_module_t 类型的 ngx_http_foo_bar_module_ctx. 假设你开发了一个 Foo Bar 模块,那么模块名称应该叫: ngx_http_foo_bar_module 命令集合的名字的命名规则: ngx_http_foo_bar…
自定义模块的编译流程 --add-module参数 configure使用--add-module参数指定添加模块目录. config脚本 由--add-module指定的目录保存为$ngx-addon-dir环境变量. 其他环境变量由$ngx-addon-dir下的config脚本提供. 局部环境变量用小写表示,例如 $ngx_addon_dir, $ngx_addon_name. 全局环境变量用大写表示,例如 $NGX_ADDON_SRCS HTTP_MODULES CORE_LIBS ..…
在configure脚本中,运行完auto/options和auto/init脚本后,接下来就运行auto/soures脚本.这个脚本是为编译做准备的. 目录 核心模块 事件模块 OpenSSL 模块相关变量 事件驱动模块 操作系统相关项 HTTP 模块 邮件模块 Google PerfTools 模块 C++ 测试模块 1 核心模块 1.1 核心模块名称 CORE_MODULES CORE_MODULES变量记录 Nginx 的核心模块,默认包括ngx_core_module.ngx_errl…