Nginx processes HTTP requests in multiple phases. In each of the phases there might be 0 or more handlers called. In the Nginx source code phases have specific constants associated with them. Here is a list of all phases:
NGX_HTTP_SERVER_REWRITE_PHASE — the phase of request URI transformation on the virtual server level;
NGX_HTTP_FIND_CONFIG_PHASE — the phase of the configuration location lookup;
NGX_HTTP_REWRITE_PHASE — the phase of request URI transformation on the location level;
NGX_HTTP_POST_REWRITE_PHASE — request URI transformation post-processing phase;
NGX_HTTP_PREACCESS_PHASE — access restrictions check preprocessing phase;
NGX_HTTP_ACCESS_PHASE — access restrictions check phase;
NGX_HTTP_POST_ACCESS_PHASE — access restrictions check post-processing phase;
NGX_HTTP_TRY_FILES_PHASE — try_files directive processing phase;
NGX_HTTP_CONTENT_PHASE — content generation phase;
NGX_HTTP_LOG_PHASE — logging phase.
On every phase you can register any number of your handlers. Exceptions are following phases:
NGX_HTTP_FIND_CONFIG_PHASE. On this phase no handlers are called, instead a search for configuration location is performed and “Location” request header is filled.
NGX_HTTP_POST_ACCESS_PHASE. On this phase no handlers are called,
only the result of access checks is interpreted and applied. The phase is required to implement directive satisfy all/any.
NGX_HTTP_POST_REWRITE_PHASE. On this phase no handlers are called,
instead request URI transformation post-processing is performed;
NGX_HTTP_TRY_FILES_PHASE. On this phase no handlers are called,
instead Nginx processes the try_files directive.
Each phase has a list of handlers associated with it. Once registered on a phase, handler can return one of the following values:
NGX_OK — the request has been successfully processed, request must be routed to the next phase;
NGX_DECLINED — request must be routed to the next handler;
NGX_AGAIN, NGX_DONE — the request has been successfully processed, the request must be suspended until some event (e.g., subrequest finishes, socket becomes writeable or timeout occurs) and handler must be called again;
NGX_ERROR, NGX_HTTP_… — an error has occurred while processing the request.