Lesson 25 / 25
Revision and Interview Questions
Recall NGINX concepts quickly for exams and interviews.
Cheat sheet
Architecture: master + workers, event-driven non-blocking I/O; worker_processes auto, worker_connections. Operations: nginx -t, nginx -T, graceful reload. Config: contexts main/events/http/server/location/stream; inheritance, except array directives like add_header and proxy_set_header that are replaced entirely when redefined. Server selection: listen, then exact, leading wildcard, trailing wildcard, regex server_name, else default_server. Locations: = exact; longest prefix, ^~ stops regex; regexes ~/~* in file order, first wins; else longest prefix. Static: root appends URI, alias replaces prefix; try_files (SPA fallback to /index.html); expires. Proxy: proxy_pass with or without URI part; Host, X-Real-IP, X-Forwarded-For, X-Forwarded-Proto; timeouts; buffering; WebSocket Upgrade/Connection headers; fastcgi_pass for PHP-FPM. Load balancing: round robin, weight, least_conn, ip_hash, hash ... consistent, random two; max_fails/fail_timeout, backup, keepalive; proxy_next_upstream (no POST retries by default); stream for TCP/UDP. TLS: TLS 1.2/1.3, full chain, Certbot, http2 on, listen 443 quic + Alt-Svc for HTTP/3, return 301, HSTS. Performance: proxy cache with use_stale and lock, gzip/gzip_static, keepalive, buffers. Security: limit_req with burst/nodelay and 429, limit_conn, client_max_body_size, allow/deny, auth_basic, auth_request, security headers with always, server_tokens off. Observability: JSON logs with $request_time and $upstream_response_time, stub_status.
Common interview questions
Answer with configuration snippets where possible.
1. How does NGINX handle many concurrent connections efficiently?
2. How does NGINX choose a server block and then a location block?
3. What is the difference between root and alias?
4. What changes when proxy_pass has a trailing slash?
5. Which headers should a reverse proxy forward to the application, and why?
6. Compare round robin, least_conn, ip_hash and consistent hashing.
7. How do you proxy WebSockets through NGINX?
8. How do you configure rate limiting, and what do burst and nodelay do?
9. How would you cache API responses safely?
10. How do you reload configuration without dropping connections?Answer with the precedence rules
Many NGINX interview questions are really about precedence: server_name matching, location matching and directive inheritance. Stating those rules precisely, with an example, stands out.
Quick check: Which location type is checked first and wins immediately when it matches?
- A regex location with ~*
- A prefix location with ^~
- The longest plain prefix
- An exact match location with =
Answer
An exact match location with = — Exact matches (=) are selected immediately, before any prefix or regex evaluation.