Report this

What is the reason for this report?

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

Posted on February 17, 2021

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);

  • h = ngx_http_hello_handler;
    where cmcf-> phases [NGX_HTTP_CONTENT_PHASE].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 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?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.