Now, you should be prepared to look at Nginx's real module and wonder how Nginx works. See Nginx source code is necessary, choose a function and you want to do the similar module, understand it, and then imitate it, to achieve it, is not very simple.
Emiller not write an in-depth reading of the Nginx module of the article, absolutely not, this is an application-oriented article, I recorded their own insights, and write their own modules, and share with the world.
First, you need a directory to put your module, preferably not in the N Ginx code directory. You need at least two files in your directory:
· "Config"
· "Ngx_http_<your module>_module.c"
The config file is included in the./configure configuration and requires some configuration.
Filter module "config" file:
Ngx_addon_name=ngx_http_<your Module>_module
http_aux_filter_modules= "$HTTP _aux_filter_modules ngx_http_<your module>_module"
ngx_addon_srcs= "$NGX _addon_srcs $ngx _addon_dir/ngx_http_<your module>_module.c"
"Config" file for other modules:
Ngx_addon_name=ngx_http_<your Module>_module
http_modules= "$HTTP _modules ngx_http_<your module>_module"
ngx_addon_srcs= "$NGX _addon_srcs $ngx _addon_dir/ngx_http_<your module>_module.c"
As for the C source file, I suggest directly to the code similar to the module, and then renamed, Modify, to meet your requirements on it.
Now start compiling:
./configure–add-module=path/to/your/new/module/directory
Make
Make install
If you need to add a library file, just add the command to the config file:
core_libs= "$CORE _libs-lfoo"
Foo is the name of the library you want to join.
If you have any good stuff done, send it to the Nginx mailing list and share it with you.