内容简介:实战开发一个Nginx扩展 (Nginx Module)
实战开发一个Nginx扩展 (Nginx Module)
repo地址 https://github.com/wujunze/ng...
nginx_module_echo
使用echo指令输出一个字符串
Nginx 版本
Nginx1.0.10 https://github.com/nginx/ngin...
开发环境
OS : CentOS Linux release 7.2.1511 (Core)
安装一个干净的 Nginx
-
下载 Nginx10.10 并且解压它
-
安装gcc和Nginx需要的lib
-
./configure --prefix=/usr/local/nginx && make && make install
-
运行Nginx
定义模块配置结构
typedef struct {
ngx_str_t ed; //该结构体定义在这里 https://github.com/nginx/nginx/blob/master/src/core/ngx_string.h
} ngx_http_echo_loc_conf_t;
定义echo模块的指令和参数转化函数
定义模块Context
-
定义ngx_http_module_t类型的结构体变量
-
初始化一个配置结构体
-
将其父block的配置信息合并到此结构体 实现了配置的继承
编写Handler 模块真正干活儿的部分
组合Nginx Module
整理模块代码 按照Nginx官方规范
编写config文件
ngx_addon_name=ngx_http_echo_module HTTP_MODULES="$HTTP_MODULES ngx_http_echo_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_echo_module.c"
编译安装echo模块
./configure --prefix=/usr/local/nginx/ --add-module=/root/ngx_dev && make && make install
安装成功
修改Nginx配置文件测试Module
Nginx echo Module 运行成功
如果这个repo对你有帮助 欢迎star fork Thanks
参考文档
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- ECMASCRIPT 6 实战之 扩展运算符
- Thinkphp实战利用钩子使用行为扩展 (Hook)
- Django2 Web实战01-启动项目-model 扩展
- 【php 扩展开发】扩展生成器
- 喧喧发布 1.6.0 版本,扩展机制增强,支持服务器扩展
- 为vscode编写扩展
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Smashing Book
Jacob Gube、Dmitry Fadeev、Chris Spooner、Darius A Monsef IV、Alessandro Cattaneo、Steven Snell、David Leggett、Andrew Maier、Kayla Knight、Yves Peters、René Schmidt、Smashing Magazine editorial team、Vitaly Friedman、Sven Lennartz / 2009 / $ 29.90 / € 23.90
The Smashing Book is a printed book about best practices in modern Web design. The book shares technical tips and best practices on coding, usability and optimization and explores how to create succes......一起来看看 《The Smashing Book》 这本书的介绍吧!