Home › Blog › Nginx Interview Questions (2026): 30 Questions on Reverse Proxy, Location Blocks and Tuning

Nginx Interview Questions (2026): 30 Questions on Reverse Proxy, Location Blocks and Tuning

Nginx interview questions focus on how it works as a web server and reverse proxy: the master and worker process model, how a location block is chosen, what proxy_pass does to the URI, upstream load balancing, TLS, caching and rate limits, and how to debug 502, 504 and 413 errors. Strong answers name the real directive and the default it changes.

Nginx interview questions focus on how it works as a web server and reverse proxy: the master and worker process model, how a location block is chosen, what proxy_pass does to the URI, upstream load balancing, TLS, caching and rate limits, and how to debug 502, 504 and 413 errors. Strong answers name the real directive and the default it changes.

Below are 30 questions by level with short answers and config snippets, three troubleshooting scenarios and how interviews test the tool. Directive defaults are as nginx.org documented them for open-source nginx on November 17, 2026; F5 also sells a commercial edition, NGINX Plus. Linux fundamentals that come up alongside are in Linux interview questions.

Nginx fundamentals: questions 1–9

  1. What is Nginx used for? An event-driven web server, reverse proxy, load balancer and HTTP cache. Typical jobs: TLS termination in front of app servers, serving static files, routing paths to different services, and Kubernetes ingress.
  2. Explain the master and worker processes. The master reads the config, binds ports and manages workers; workers handle connections in a non-blocking event loop (epoll on Linux). worker_processes auto; starts one per CPU core and worker_connections caps connections per worker.
  3. Why does Nginx handle many connections cheaply? Each worker multiplexes thousands of connections in one event loop instead of a thread or process per client, so idle keep-alive connections cost little memory. Blocking work such as slow disk reads can stall a worker, which is why thread pools exist.
  4. How is the configuration structured? Nested contexts: main, events, http, server, location, plus upstream and stream for TCP and UDP. Directives inherit downward, but array-type ones like proxy_set_header are replaced, not merged, once a lower level defines any.
  5. How do you change config safely? nginx -t validates syntax and referenced files; nginx -s reload or systemctl reload nginx starts new workers with the new config while old workers finish their requests, so no traffic is dropped. nginx -T prints the full effective config.
  6. How does Nginx choose a server block? It matches the listen address and port, then the Host header against server_name: exact name, longest wildcard starting with an asterisk, longest wildcard ending with one, then the first matching regex; otherwise the default_server for that port.
  7. root vs alias? root appends the full URI to the path; alias replaces the matched location prefix. With location /img/ { alias /data/images/; }, /img/a.png serves /data/images/a.png; with root /data/images; it would look for /data/images/img/a.png.
  8. What does try_files do? Checks files in order and serves the first that exists, falling back to the last argument. try_files $uri $uri/ /index.html; is the usual single-page-app rule; ending with =404 returns a status instead.
  9. Why put a reverse proxy in front of an app? TLS termination, buffering slow clients so app workers are freed quickly, caching and compression, load balancing, and one place for security headers, body-size limits and rate limits.

Intermediate Nginx questions: 10–18

  1. How is a location block chosen? An exact match with = ends the search. Otherwise Nginx remembers the longest matching prefix; if it has ^~, regexes are skipped. Then regex locations (~ case-sensitive, ~* insensitive) are tried in file order and the first match wins; if none matches, the remembered prefix is used.
  2. What is the trailing-slash trap in proxy_pass? If proxy_pass includes a URI, the matched location prefix is replaced by it: location /api/ { proxy_pass http://app/; } sends /api/users upstream as /users. Without a URI (proxy_pass http://app;) the original URI passes through unchanged.
  3. Which headers should you set when proxying? The default sends Host $proxy_host, so set proxy_set_header Host $host;, plus X-Real-IP $remote_addr, X-Forwarded-For $proxy_add_x_forwarded_for and X-Forwarded-Proto $scheme, so the app sees the real client and scheme.
  4. Which load-balancing methods exist? Weighted round robin by default, least_conn, ip_hash for stickiness by client address, hash $key consistent and random. Per-server options include weight, backup, max_fails and fail_timeout.
  5. How do passive health checks work? With the defaults max_fails=1 and fail_timeout=10s, one failed attempt marks a server unavailable for 10 seconds. Active health checks with the health_check directive are part of the commercial subscription, according to nginx.org.
  6. How do you proxy WebSockets? Pass the upgrade handshake: proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; and raise proxy_read_timeout for long-lived connections. Older nginx versions defaulted to HTTP/1.0 upstream, so set the version explicitly.
  7. How do you set up TLS and HTTP/2? listen 443 ssl; with ssl_certificate and ssl_certificate_key, ssl_protocols TLSv1.2 TLSv1.3;, and the separate http2 on; directive, available since nginx 1.25.1. Redirect port 80 with return 301 https://$host$request_uri;.
  8. How does rate limiting work? limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; defines a leaky-bucket zone in shared memory and limit_req zone=api burst=20 nodelay; applies it. Rejected requests get 503 by default, so many teams set limit_req_status 429;.
  9. How do you cache upstream responses? proxy_cache_path /var/cache/nginx keys_zone=app:10m max_size=1g inactive=60m;, then proxy_cache app; and proxy_cache_valid 200 10m; in the location. Log $upstream_cache_status to see HIT or MISS, and use proxy_cache_use_stale to keep serving when the backend fails.

Experienced Nginx questions: 19–27

  1. 502 vs 504? 502 Bad Gateway: Nginx got no valid response because the upstream refused the connection, crashed, closed early or replied badly. 504 Gateway Timeout: it connected but the upstream didn't answer within proxy_read_timeout, 60 seconds by default. The error log says which.
  2. What causes a 413 and how do you fix it? The request body exceeded client_max_body_size, which defaults to 1m. Raise it in the right server or location, and check the limits in front (a cloud load balancer) and behind (the app framework) too.
  3. How do you tune Nginx for high traffic? worker_processes auto, enough worker_connections and worker_rlimit_nofile, upstream keepalive, sendfile, sensible gzip levels, caching, and kernel settings such as the listen backlog. Load-test before and after; don't paste tuning from blogs.
  4. Why configure upstream keepalive? Without it Nginx opens a new TCP, and possibly TLS, connection to the backend for every request. keepalive 32; in the upstream with HTTP/1.1 and an empty Connection header reuses connections, cutting latency and ephemeral-port use.
  5. Why is if inside a location risky? It isn't a general programming construct: only return and rewrite ... last are reliably safe inside it, and other directives can behave unexpectedly. Prefer map, separate locations or try_files.
  6. What is map for? Building a variable from another one, evaluated only when used: mapping a cookie or header to a backend name, or setting $connection_upgrade for WebSockets. It lives in the http context and replaces chains of if.
  7. How do you deploy behind Nginx without downtime? Drain a backend (mark it down and reload), deploy, health-check, then return it; or switch between blue and green upstreams with a reload, which is graceful. For an nginx binary upgrade, the USR2 signal starts a new master alongside the old one.
  8. How would you harden an Nginx server? TLS 1.2 and 1.3 only, HSTS, server_tokens off;, security headers, body-size and method limits, rate limits on login endpoints, deny dotfiles with location ~ /\. { deny all; }, unprivileged workers, and prompt patching.
  9. What should you know about Nginx as Kubernetes ingress? A controller generates nginx config from Ingress resources and annotations, so debugging means reading the generated config and controller logs. The Kubernetes blog says best-effort maintenance of the community ingress-nginx project ended in March 2026, with no further releases or security fixes; it is separate from F5's NGINX Ingress Controller, and many teams are moving to Gateway API.

Nginx scenario and troubleshooting questions: 28–30

  1. Users get intermittent 502s right after each deploy. Read the error log for the exact message (connect() failed, upstream prematurely closed connection, no live upstreams). Check whether backends stop before Nginx stops sending to them, whether the app's keep-alive timeout is shorter than Nginx's, and whether ports or sockets changed. Fix with draining, matched timeouts and health checks.
  2. Static files return 404 but exist on disk. Usually root vs alias, a regex location catching the path first, or file permissions or SELinux for the worker user. The error log prints the full path it tried; confirm with curl -I and nginx -T.
  3. The app logs every request as coming from 127.0.0.1. Nginx isn't forwarding the client address, or it sits behind another proxy. Set X-Forwarded-For and X-Real-IP; behind a load balancer, use set_real_ip_from with only the trusted proxy ranges and real_ip_header X-Forwarded-For;.

How interviews test Nginx

RoundWhat they askWhat a strong answer shows
ScreenReverse proxy basics, reload vs restart, root vs aliasAccurate definitions and the right command
Technical roundWrite a server block that terminates TLS and proxies /api/ to two backendsCorrect proxy_pass, headers and upstream syntax
Troubleshooting round502s, 504s, 413s, wrong client IPsStarting from the error log and naming the directive involved
Senior roundCaching, rate limiting, zero-downtime deploys, ingressTrade-offs and measurement, not copied tuning

Candidates for DevOps and platform roles commonly report a live config-reading exercise: here is a block, what happens to this request? Practise by running nginx in a container, as in Docker interview questions, and curling it with different paths. Broader context is in DevOps interview questions and system administrator interview questions.

Where CoPilot Interview fits

CoPilot Interview is an AI interview assistant whose free AI mock interview builds Nginx and web infrastructure questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10, which is a quick way to find the answers above that you can't yet explain without notes. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. The browser demo at /try has 145 practice questions in 10 tracks with typed answers scored out of 10, no signup needed. Paid plans are Standard at $24.99 a month and Pro at $39.99 a month, and the desktop app runs on Windows 10 and 11 and macOS 12 or later. Technical screens, take-home tasks, online assessments and proctored tests usually forbid outside help, so prepare for those rather than use any tool during them; in any live interview, follow your employer's rules.

Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.

Frequently asked questions

What are the most common Nginx interview questions?

Location matching order, the <code>proxy_pass</code> trailing slash, 502 vs 504, which proxy headers to set, load-balancing methods, reload vs restart, and how to test a config with <code>nginx -t</code>.

What is the difference between Nginx and Apache?

Nginx uses an event-driven worker model and central configuration; Apache uses multi-processing modules (prefork, worker, event) and allows per-directory <code>.htaccess</code> overrides. Both can serve static files and reverse-proxy.

What is the difference between reload and restart?

Reload re-reads the config and replaces workers gracefully without dropping connections; restart stops and starts the whole service, briefly refusing connections. Always run <code>nginx -t</code> first.

Do I need to know NGINX Plus for an interview?

Only if the job mentions it. Know that some features, such as active health checks with the <code>health_check</code> directive, are commercial, and answer the rest with open-source directives.

Practice this interview before the real one

The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.

Start a mock interview