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
-
Download Nginx10.10 and unzip it
-
Install GCC and lib required by Nginx
-
./configure –prefix=/usr/local/nginx && make && make install
-
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
-
Define a structure variable of type ngx_HTTP_module_T
-
Initialize a configuration structure
-
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
wiki.nginx.org/Configu…
tengine.taobao.org/book/
blog.codinglabs.org/ar…
www.nginx.com/resourc…
— — — — — — — — — — — — — — — — — — — — — — — — — I’m line — — — — — — — — — — — — — — — — — — — — — — — — –
Hard wide time (Nginx interested children can see below)
Nginx series course index
-
How does Nginx communicate with PHP
-
How to best use Nginx and Nginx configuration
-
In-depth understanding of the Nginx kernel and how Nginx works, analyzing the secrets of Nginx performance
-
Let’s develop an extension to Nginx together