---
title: Nginx Interview Questions and Answers (2026)
description: Real Nginx interview questions — the event-driven model, reverse proxy vs load balancer, location matching, 502 debugging and TLS — with config and a prep plan.
url: https://usegreenroom.app/blog/nginx-interview-questions
last_updated: 2026-07-31
---

← Back to blog

DevOps

# Nginx interview questions and answers

July 31, 2026 · 12 min read

![Nginx interview questions and answers guide — cover from Greenroom, the AI mock interviewer](/assets/blog/nginx-interview-questions-hero.webp)

"Users are getting 502s," the interviewer said. "Nginx logs show it, the app logs show nothing. Where do you look?" The candidate said he'd restart Nginx. The interviewer waited. The point of a 502 is that Nginx is fine — it is telling you, quite precisely, that the thing behind it did not answer.

<strong>Nginx interview questions</strong> reward people who read error codes as evidence rather than as noise. Nginx sits in front of nearly every production stack, so DevOps, SRE and backend loops all ask about it. This guide covers the architecture, reverse proxying and load balancing, location matching, the 502 family, and TLS.

## What Nginx interviews actually test

<strong>Nginx interview questions</strong> cluster into five bands:

- <strong>Architecture</strong> — why the event-driven model beats thread-per-connection, master and worker processes.
- <strong>Proxying and load balancing</strong> — upstreams, algorithms, health checks, headers.
- <strong>Request matching</strong> — <code>location</code> precedence, <code>root</code> vs <code>alias</code>, rewrites.
- <strong>Debugging</strong> — the 4xx/5xx family, especially 502, 504 and 413.
- <strong>TLS, caching and hardening</strong> — termination, HTTP/2, rate limiting, headers.

![Nginx interview question topics diagram — event-driven architecture, reverse proxy and load balancing, location matching, error debugging, TLS and caching](/assets/blog/nginx-interview-questions-diagram.webp)

The five bands of Nginx interview questions, with error debugging deciding most SRE-leaning rounds.

## Architecture: why Nginx scales

The classic opener is "why is Nginx faster than Apache?", and the honest answer is about the concurrency model rather than raw speed. Apache's traditional prefork model dedicates a process or thread per connection, so ten thousand idle keep-alive connections cost ten thousand threads' worth of memory and scheduling. Nginx uses a small number of single-threaded <strong>worker processes</strong>, each running an event loop over <code>epoll</code> or <code>kqueue</code>, so one worker handles thousands of concurrent connections because most are idle at any instant.

Follow-ups worth having ready: the <strong>master process</strong> reads config, binds privileged ports and manages workers, while workers handle traffic as an unprivileged user — which is why a config reload can happen without dropping connections (<code>nginx -s reload</code> starts new workers and lets old ones drain). Set <code>worker_processes auto</code> to match CPU cores. And be fair: Apache with the event MPM closed much of the gap, so the real reasons teams pick Nginx today are configuration style, memory footprint and its strength as a reverse proxy.

## Reverse proxy, load balancer, and the headers people forget

Expect "what is the difference between a reverse proxy and a load balancer?" A reverse proxy sits in front of servers and forwards client requests to them, adding TLS termination, caching, compression and buffering. A load balancer distributes traffic across multiple backends for capacity and availability. Nginx does both, and load balancing is really a feature of its proxying — a reverse proxy with one backend is not a load balancer.

```
upstream app_backend {
    least_conn;                      # better than round robin for uneven request costs
    server 10.0.1.11:8000 max_fails=3 fail_timeout=30s;
    server 10.0.1.12:8000 max_fails=3 fail_timeout=30s;
    server 10.0.1.13:8000 backup;
    keepalive 32;                    # reuse upstream connections
}

server {
    listen 443 ssl http2;
    server_name api.example.com;

    location / {
        proxy_pass http://app_backend;

        # Without these the app sees Nginx's IP and thinks every request is HTTP
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_connect_timeout 5s;
        proxy_read_timeout    60s;
    }
}
```

The <code>proxy_set_header</code> block is the most-asked practical detail. Without it your application logs every request as coming from the proxy's IP, rate limiting by client IP breaks, and frameworks generate <code>http://</code> redirect URLs on an HTTPS site — a bug that appears as an infinite redirect loop and is a favourite scenario question.

Know the balancing algorithms: <strong>round robin</strong> (default), <strong>least_conn</strong> (best when request durations vary), <strong>ip_hash</strong> (sticky sessions by client IP — and be ready to say that sticky sessions are a workaround for stateful apps, and externalising session state to Redis is the better fix), and weighted variants.

## Location matching, root vs alias

A reliable trick question, because the precedence is not top-to-bottom. Nginx evaluates <code>location</code> blocks in this order: exact match <code>=</code> wins immediately; then the longest prefix match is remembered; if that prefix used <code>^~</code>, it wins; otherwise regex locations (<code>~</code> case-sensitive, <code>~*</code> case-insensitive) are tried <em>in file order</em> and the first match wins; if no regex matches, the remembered prefix match is used.

Then <strong><code>root</code> vs <code>alias</code></strong>, which trips up nearly everyone. With <code>root /var/www</code> inside <code>location /static/</code>, a request for <code>/static/a.png</code> serves <code>/var/www/static/a.png</code> — the location path is appended. With <code>alias /var/www/</code>, the location path is replaced, so the same request serves <code>/var/www/a.png</code>. Interviewers ask because the difference silently produces 404s.

Also know <code>try_files $uri $uri/ /index.html</code> — the single-page-app fallback that makes client-side routing work on refresh, and one of the most common real configurations you will be asked to write.

## Debugging: 502, 504, 413 and friends

Back to the intro. The error-code band is where SRE-leaning interviews concentrate, and each code points somewhere specific:

- <strong>502 Bad Gateway</strong> — Nginx reached the upstream but got an invalid or no response. Usually the backend is down, crashed, listening on a different port, or bound to <code>127.0.0.1</code> inside a container while Nginx dials its container IP. Check the backend first, not Nginx.
- <strong>504 Gateway Timeout</strong> — the upstream accepted the connection but did not respond within <code>proxy_read_timeout</code>. This is a slow application, not a broken one. Raising the timeout hides it; find the slow query.
- <strong>413 Request Entity Too Large</strong> — <code>client_max_body_size</code> (default 1MB) is smaller than the upload. The classic "file uploads fail over about a megabyte" scenario.
- <strong>499</strong> — an Nginx-specific code meaning the client closed the connection before a response. Usually the user gave up on something slow, or an aggressive client timeout.
- <strong>403</strong> — commonly filesystem permissions or SELinux, not the config.
- <strong>Connection refused in the error log</strong> — the upstream is not listening at all.

The process answer matters as much as the codes: check <code>/var/log/nginx/error.log</code> first (it names the upstream and the reason), then verify the backend is listening with <code>curl</code> from the Nginx host, then <code>nginx -t</code> to validate config before any reload. Candidates who say "I'd restart it" lose the round; candidates who say "a 502 means Nginx is working and the backend isn't" have obviously been on call. Our <a href="/blog/site-reliability-engineer-interview-questions">SRE interview questions guide</a> covers the wider incident material.

## TLS, caching, rate limiting and hardening

The production band. Know <strong>TLS termination</strong> — Nginx decrypts and forwards plaintext to backends inside a trusted network, which centralises certificate management and offloads crypto. Know that HTTP/2 requires TLS in practice, and what it buys (multiplexing over one connection, so domain sharding and file concatenation became counterproductive).

Know <strong>rate limiting</strong> with <code>limit_req_zone</code> and the leaky-bucket model, including the <code>burst</code> and <code>nodelay</code> parameters — a common practical question is "how would you stop one client hammering the login endpoint?" Know <strong>caching</strong> with <code>proxy_cache</code>, and <code>gzip</code>. And know the security headers you would set: HSTS, <code>X-Content-Type-Options</code>, a CSP, plus <code>server_tokens off</code> to stop advertising the version.

For modern deployments, be ready for "why Nginx when Kubernetes has ingress?" — the honest answer is that the most common ingress controller <em>is</em> Nginx, so the concepts transfer directly. Our <a href="/blog/kubernetes-interview-questions">Kubernetes interview questions guide</a> covers that layer.

## The docs, a real server, ChatGPT — where each fits

- <strong>The official Nginx documentation and admin guide</strong> — dry but authoritative, and the source of the location-precedence rules people get wrong.
- <strong>DigitalOcean's Nginx tutorials</strong> — the best practical walkthroughs for config patterns.
- <strong>Mozilla's SSL Configuration Generator</strong> — produces sane TLS config and is worth naming in an interview.
- <strong>Breaking a real server</strong> — highest yield. Run Nginx in front of an app in Docker, stop the app and read the 502 in the error log, set <code>client_max_body_size</code> to 1k and watch uploads 413. You will never forget which code means what.
- <strong>GeeksforGeeks-style dumps</strong> — fine for definitions, useless for the debugging band that decides the round.
- <strong>ChatGPT</strong> — good for generating config and explaining directives. It will not tell you the app logs are empty and wait for you to work out what that implies.
- <strong>Greenroom</strong> — the spoken layer. <a href="/">Ari, the AI interviewer</a>, runs incident-style rounds out loud and pushes when your answer is an action rather than a diagnosis. Fair tradeoff: Ari will not read your access logs.

> The core truth: Nginx interviews are diagnostic interviews. Every error code is evidence about which layer failed, and the candidate who says "a 502 means Nginx is healthy and the upstream isn't" has already answered better than one who reaches for a restart.

## How to prepare for an Nginx interview

- <strong>Week 1:</strong> architecture and config basics. Explain the event-driven model aloud, and write a reverse-proxy server block from memory including the forwarded headers.
- <strong>Week 2:</strong> matching rules. Drill <code>location</code> precedence and <code>root</code> vs <code>alias</code> until they are automatic, and write the SPA <code>try_files</code> fallback.
- <strong>Week 3:</strong> break things deliberately — produce a 502, a 504, a 413 and a redirect loop, and practise diagnosing each from symptoms alone.
- <strong>Final week:</strong> TLS, rate limiting and caching config, plus two full spoken mocks with incident-style follow-ups.

Building the rest of the stack? The <a href="/blog/docker-interview-questions">Docker</a> and <a href="/blog/kubernetes-interview-questions">Kubernetes</a> guides cover the container layer, the <a href="/blog/fastapi-interview-questions">FastAPI guide</a> covers a typical upstream, the <a href="/blog/prometheus-interview-questions">Prometheus guide</a> covers monitoring it, and the <a href="/blog/devops-engineer-interview-questions">DevOps engineer interview questions guide</a> covers the wider loop.

## Frequently asked questions

### What are the most common Nginx interview questions?

The most common questions cover why the event-driven worker model scales better than thread-per-connection, the difference between a reverse proxy and a load balancer, which proxy headers you must set and what breaks without them, how location block precedence actually works, the difference between root and alias, and what specific error codes such as 502, 504 and 413 tell you about which layer failed.

### What causes a 502 Bad Gateway in Nginx and how do you debug it?

A 502 means Nginx successfully ran but received an invalid response or no response from the upstream, so the problem is almost always the backend rather than Nginx. Common causes are the application being down or crashed, listening on a different port, or bound to 127.0.0.1 inside a container while Nginx dials the container IP. Debug by reading the Nginx error log, which names the upstream and reason, then curl the backend directly from the Nginx host.

### What is the difference between root and alias in Nginx?

With root, the location path is appended to the root path, so root /var/www inside location /static/ serves /static/a.png from /var/www/static/a.png. With alias, the location path is replaced, so alias /var/www/ inside the same location serves that request from /var/www/a.png. Confusing the two silently produces 404s, which is why it is a common interview question.

### How does location block precedence work in Nginx?

Nginx does not simply match top to bottom. An exact match using the equals modifier wins immediately. Otherwise the longest matching prefix is remembered, and if that prefix used the caret-tilde modifier it wins outright. If not, regex locations are tried in the order they appear in the file and the first match wins. If no regex matches, the remembered longest prefix match is used.

### Which proxy headers should you set in Nginx and why?

Set Host, X-Real-IP, X-Forwarded-For and X-Forwarded-Proto. Without them the application sees the proxy's IP as the client address, so logging and IP-based rate limiting break, and the app believes every request arrived over plain HTTP. That last one causes frameworks to generate http:// redirect URLs on an HTTPS site, which presents as an infinite redirect loop and is a common scenario question.

### What is the difference between 502 and 504 in Nginx?

A 502 Bad Gateway means Nginx could not get a valid response from the upstream at all — typically the backend is down, refused the connection, or returned garbage. A 504 Gateway Timeout means the upstream accepted the connection but did not respond within proxy_read_timeout, indicating a slow application rather than a broken one. Raising the timeout on a 504 hides the symptom; the real fix is finding the slow operation.

Nginx rounds reward reading the error code as evidence, out loud. Greenroom runs mock DevOps and SRE interviews with Ari — incident follow-ups included — and scores structure, clarity and depth. Free to start. Curious how it works? See how AI mock interviews work.
