Web / NGINX Interview questions
Explain the lifecycle of an HTTP request in NGINX?
Every request NGINX handles moves through a defined sequence of processing stages, regardless of whether it ends up being served locally or proxied elsewhere.
First, NGINX accepts the TCP connection and, if TLS is involved, completes the SSL handshake. It then reads and parses the HTTP request line and headers. Using the Host header and listening port, it selects the matching server block, then within that block selects the most specific matching location block for the request URI.
From there, the request runs through NGINX's internal processing phases - rewrite rules are applied, access controls are checked, and then content is generated: either read from disk for static files, or forwarded upstream via proxy_pass for dynamic content. The response is filtered (compression, header addition) before being written back to the client, and the connection is either closed or kept alive for the next request.
flowchart TD
A[Accept connection / TLS handshake] --> B[Parse request line and headers]
B --> C[Match server block by Host + port]
C --> D[Match location block by URI]
D --> E[Rewrite phase]
E --> F[Access control phase]
F --> G{Static or proxied?}
G -- Static --> H[Read file from disk]
G -- Proxied --> I[proxy_pass to upstream]
H --> J[Response filters: compression, headers]
I --> J
J --> K[Write response to client]
More Related questions...