nginx_http_core_phase_event_handler
Overview
nginx provides several phases for developer, developer can register its own handler to some phases, do its own work without breaking nginx source code, it’s flexible, here are phases with order(runs from top to bottom).
- NGX_HTTP_SERVER_REWRITE_PHASE
- NGX_HTTP_FIND_CONFIG_PHASE
- NGX_HTTP_REWRITE_PHASE
- NGX_HTTP_POST_REWRITE_PHASE
- NGX_HTTP_PREACCESS_PHASE
- NGX_HTTP_ACCESS_PHASE
- NGX_HTTP_POST_ACCESS_PHASE
- NGX_HTTP_PRECONTENT_PHASE
- NGX_HTTP_CONTENT_PHASE
- NGX_HTTP_LOG_PHASE
each phase has a checker, nginx phase engine runs the checker with fixed order, inside each checker there could be several handlers, each checker runs handlers of that phase.
Note: phase is for client request(filter is for response), engine runs after parsing all request headers.
HTTP
phase
Data Structure
1 | typedef struct ngx_http_phase_handler_s ngx_http_phase_handler_t; |
API
1 | // construct runtime phase engine |
event handler
For http request, the event handler changes during what it’s processing, process header or process body, here is diagram shows how they are changing during processing request.