Nginx Module (Nginx Module)

Repo addressGithub.com/wujunze/ng….

nginx_module_echo

Output a string using the echo command

Nginx version

Nginx1.0.10 Github.com/nginx/ngin….

The development environment



OS : CentOS Linux release 72.1511. (Core)Copy the code



Install a clean Nginx

  1. Download Nginx10.10 and unzip it

  2. Install GCC and lib required by Nginx

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



  1. Run Nginx

Define the module configuration structure



typedef struct {
    ngx_str_t ed;  //The structure is defined herehttps://github.com/nginx/nginx/blob/master/src/core/ngx_string.h
} ngx_http_echo_loc_conf_t;Copy the code

Defines the echo module’s instruction and parameter conversion functions

Define the module Context

  1. Define a structure variable of type ngx_HTTP_module_T

  2. Initialize a configuration structure

  3. Merging the configuration information of its parent block into this structure implements configuration inheritance

Writing the Handler module does the real work

Combination Nginx Module

Collate module code according to Nginx official specification

Writing the Config file



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"Copy the code

Compile and install the Echo module



 ./configure --prefix=/usr/local/nginx/ --add-module=/root/ngx_dev && make && make installCopy the code

Successful installation

Modify the Nginx configuration file test Module

The Nginx Echo Module is running successfully

If this repo is helpful to you welcome star Fork Thanks

Reference documentation

  1. wiki.nginx.org/Configu…

  2. tengine.taobao.org/book/

  3. blog.codinglabs.org/ar…

  4. www.nginx.com/resourc…

— — — — — — — — — — — — — — — — — — — — — — — — — I’m line — — — — — — — — — — — — — — — — — — — — — — — — –

Hard wide time (Nginx interested children can see below)

Nginx series course index

  1. How does Nginx communicate with PHP

  2. How to best use Nginx and Nginx configuration

  3. In-depth understanding of the Nginx kernel and how Nginx works, analyzing the secrets of Nginx performance

  4. Let’s develop an extension to Nginx together