Nginx — Reverse Proxy, Static Hosting & Load Balancer
Three Nginx configurations covering real-world use cases: static content hosting, reverse proxy to a backend service, and upstream load balancing — each runnable with docker compose up.

Three Nginx configurations covering real-world use cases: static content hosting, reverse proxy to a backend service, and upstream load balancing — each runnable with docker compose up.

Problem
Most engineers use Nginx as a black box. This project builds intuition for how traffic flows: from client to Nginx, through to backend services, and how Nginx makes routing decisions. Three configs, each solving a distinct production pattern.
Approach
Config 1 — Static hosting: serve a React build from /var/www/html with cache headers and gzip compression.
Config 2 — Reverse proxy: forward /api/* traffic to an upstream application server, preserving Host and X-Forwarded-For headers.
Config 3 — Load balancer: distribute traffic across two upstream instances using round-robin with health check directives.
Validated each config end-to-end by running curl requests and inspecting response headers.
Documented the request flow for each config with ASCII diagrams in the README.
Results
Code
Reverse proxy config forwarding /api traffic with preserved client headers.
server {
listen 80;
server_name example.com;
location / {
root /var/www/html;
try_files $uri $uri/ /index.html;
expires 365d;
add_header Cache-Control "public, immutable";
}
location /api/ {
proxy_pass http://backend:3000/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}Stack
Why it matters