NGINX: How to register phase handler in the request processing flow after a specific standard NGINX module callback?

Posted February 17, 2021 417 views

Hi, as we know NGINX HTTP request passes through a sequence of phases like NGXHTTPPOSTREADPHASE 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 = ngxarraypush (& cmcf-> phases[NGXHTTPCONTENT_PHASE].handlers);

  • h = ngxhttphellohandler;
    where cmcf-> phases [NGX
    HTTPCONTENTPHASE].handlers is an array of handlers for the content phase. This registers our handler in the end of the array.

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 ngxhttprealipmodule registers its handler at NGXHTTPPOSTREAD_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?

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!