By lakshaygaba
Hi, as we know NGINX HTTP request passes through a sequence of phases like NGX_HTTP_POST_READ_PHASE and so on and many standard nginx modules register their phase handlers as a way to get called at a specific stage of request processing.
Now, we can build our own module and hook at any phase by doing something like: h = ngx_array_push (& cmcf-> phases[NGX_HTTP_CONTENT_PHASE].handlers);
As multiple modules can register their handlers at a single phase, I am developing a module which needs to register its handler in a specific phase and also after a specific standard nginx module call-back in the array i.e. if ngx_http_realip_module registers its handler at NGX_HTTP_POST_READ_PHASE, i want my handler to hook after this particular module in the sequence.
What would be the best approach to proceed with the same?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
It’s indeed possible to register handlers in specific phases of the HTTP request handling. However, controlling the exact ordering of handlers in a specific phase might be rather tricky, as it often depends on the order of module initializations.
Nginx does not provide a built-in facility for ordering handlers within a phase. Handlers are generally called in the order they were registered. And that order can depend on the order in which modules are listed during Nginx compilation.
You can experiment with adjusting the order of module initializations, but please note it could lead to unintended consequences.
If it’s crucial to have control over the exact order of handler calls, you may need to consider another design approach. A potential method could include combining the functionality of your custom module and ngx_http_realip_module into a single module if it suits your specific needs.
For more in-depth technical details, you may want to directly refer to the Nginx Development Guide.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.