实战开发一个Nginx扩展 (Nginx Module)

栏目: 服务器 · Nginx · 发布时间: 8年前

内容简介:实战开发一个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...

实战开发一个Nginx扩展 (Nginx Module)

开发环境

OS : CentOS Linux release 7.2.1511 (Core)

实战开发一个Nginx扩展 (Nginx Module)

实战开发一个Nginx扩展 (Nginx Module)

安装一个干净的 Nginx

  1. 下载 Nginx10.10 并且解压它

    实战开发一个Nginx扩展 (Nginx Module)

  2. 安装gcc和Nginx需要的lib

    实战开发一个Nginx扩展 (Nginx Module)

实战开发一个Nginx扩展 (Nginx Module)

  1. ./configure --prefix=/usr/local/nginx && make && make install

    实战开发一个Nginx扩展 (Nginx Module)

实战开发一个Nginx扩展 (Nginx Module)

实战开发一个Nginx扩展 (Nginx Module)

  1. 运行Nginx

    实战开发一个Nginx扩展 (Nginx Module)

实战开发一个Nginx扩展 (Nginx Module)

定义模块配置结构

typedef struct {
    ngx_str_t ed;  //该结构体定义在这里 https://github.com/nginx/nginx/blob/master/src/core/ngx_string.h
} ngx_http_echo_loc_conf_t;

实战开发一个Nginx扩展 (Nginx Module)

定义echo模块的指令和参数转化函数

实战开发一个Nginx扩展 (Nginx Module)

定义模块Context

  1. 定义ngx_http_module_t类型的结构体变量

    实战开发一个Nginx扩展 (Nginx Module)

  2. 初始化一个配置结构体

    实战开发一个Nginx扩展 (Nginx Module)

  3. 将其父block的配置信息合并到此结构体 实现了配置的继承

    实战开发一个Nginx扩展 (Nginx Module)

编写Handler 模块真正干活儿的部分

实战开发一个Nginx扩展 (Nginx Module)

组合Nginx Module

实战开发一个Nginx扩展 (Nginx Module)

整理模块代码 按照Nginx官方规范

实战开发一个Nginx扩展 (Nginx Module)

编写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扩展 (Nginx Module)

修改Nginx配置文件测试Module

实战开发一个Nginx扩展 (Nginx Module)

Nginx echo Module 运行成功

实战开发一个Nginx扩展 (Nginx Module)

如果这个repo对你有帮助 欢迎star fork Thanks


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Smashing Book

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》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具