Skip to content

A simple Nginx echo module is used to study and demonstration

License

Notifications You must be signed in to change notification settings

DoCharity/nginx-http-echo-module

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Practical development ginx Module

简体中文

nginx_module_echo

echo string

Nginx Version

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

The development environment configuration

OS : CentOS Linux release 7.2.1511 (Core)

image image

Install a clean compile Nginx

  1. Download a Nginx10.10 and unpack it image

  2. Install the GCC and the lib Nginx need image image

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

  4. Nginx run image image

Definition module configuration structure

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

#Define Nginx instruction and parameter conversion function image

definition module Context

  1. Define the type of ngx_http_module_t structure variables image
  2. Initialize a configuration structure image
  3. Will the father block configuration information incorporated into this structure Implement the configuration of inheritance image

Write the Handler really work part of the module

image

Combination Nginx module

image

Finishing module code According to the Nginx official specification

image

Write 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"

make && make install

 ./configure --prefix=/usr/local/nginx/ --add-module=/root/ngx_dev && make && make install

Successful installation

image

Modify the Nginx configuration file test Module

image

Nginx echo Module The successful running

image

If the repo help you welcome star fork Thanks!

reference

  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/

About

A simple Nginx echo module is used to study and demonstration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%