About nginx: https://nginx.org
git clone https://github.com/dedok/nginx-tutorials
cd nginx-tutorials
git clone https://github.com/nginx/nginx.git nginx
sudo apt-get install libpcre-dev zlib1-dev # install dependencies to build nginx
make configure
make
./nginx/objs/nginx
wget --server-response --header "X-My-header:1" "127.0.0.1:8081/example"
A header filter consists of three basic steps:
- Decide whether to operate on this response
- Operate on the response
- Call the next filter.
The buffer chain makes it a little tricky to write a body filter, because the body filter can only operate on one buffer (chain link) at a time. The module must decide whether to overwrite the input buffer, replace the buffer with a newly allocated buffer, or insert a new buffer before or after the buffer in question. To complicate things, sometimes a module will receive several buffers so that it has an incomplete buffer chain that it must operate on.
Content handler (Non-proxying), a file: content_handler.c Handlers typically do four things:
- get the location configuration;
- generate an appropriate response;
- send the header, and send the body. A handler has one argument, the request struct. A request struct has a lot of useful information about the client request, such as the request method, URI, and headers.
- Get NGINX NJS
- Run NGINX with conf/njs_nginx.conf configuration
- Get NJS sources
- Patch original add_header sources and complie patched NGINX
- Run compiled NGINX with conf/njs_add_header.conf configuration
The links to the examples implementation of nginx upstream: https://github.com/tarantool/nginx_upstream_module https://github.com/openresty/redis2-nginx-module
An old but the good an article about nginx anatomy: http://www.evanmiller.org/nginx-modules-guide.html#filters-body
NginX wiki: https://www.nginx.com/resources/wiki/
Tutorials of development the nginx-modules
Developed for a conference HighLoad++ 2016
if you have any questions, then reach me using email mailto: dedok.mad@gmail.com