4 Star 19 Fork 8

panda / nginx_module_echo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

nginx_module_echo

使用echo指令输出一个字符串

Nginx 版本

Nginx1.0.10 https://github.com/nginx/nginx/releases/tag/release-1.0.10 image

开发环境

OS : CentOS Linux release 7.2.1511 (Core)

image image

安装一个干净的 Nginx

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

  2. 安装gcc和Nginx需要的lib image image

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

  4. 运行Nginx image image

定义模块配置结构

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

image

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

定义模块Context

  1. 定义ngx_http_module_t类型的结构体变量 image
  2. 初始化一个配置结构体 image
  3. 将其父block的配置信息合并到此结构体 实现了配置的继承 image

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

image

组合Nginx Module

image

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

image

编写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

安装成功

image

修改Nginx配置文件测试Module

image

Nginx echo Module 运行成功

image

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

参考文档

  1. http://wiki.nginx.org/Configuration
  2. http://tengine.taobao.org/book/
  3. http://blog.codinglabs.org/articles/intro-of-nginx-module-development.html
  4. https://www.nginx.com/resources/wiki/modules/
The MIT License (MIT) Copyright (c) 2017 panda Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

A simple Nginx echo module is used to study and demonstration 展开 收起
C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/wujunze/nginx_module_echo.git
git@gitee.com:wujunze/nginx_module_echo.git
wujunze
nginx_module_echo
nginx_module_echo
master

搜索帮助