Ayodele AjimatiContact ↗
07 · DevOps & Infrastructure← All projects

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.

GitHub repository ↗4 tools · 4 measured outcomes
Nginx — Reverse Proxy, Static Hosting & Load Balancer

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

  1. 01

    Config 1 — Static hosting: serve a React build from /var/www/html with cache headers and gzip compression.

  2. 02

    Config 2 — Reverse proxy: forward /api/* traffic to an upstream application server, preserving Host and X-Forwarded-For headers.

  3. 03

    Config 3 — Load balancer: distribute traffic across two upstream instances using round-robin with health check directives.

  4. 04

    Validated each config end-to-end by running curl requests and inspecting response headers.

  5. 05

    Documented the request flow for each config with ASCII diagrams in the README.

Results

Configs implemented
3
Static asset cache
365 days (immutable)
Gzip compression
text/html, JS, CSS
Load balancer strategy
Round-robin with health check

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

  • Nginx
  • Docker
  • Bash
  • curl

Why it matters

  • Each config is isolated — clone and run docker compose up to test any of the three.
  • X-Forwarded-For and Host headers correctly forwarded for upstream session compatibility.
  • README explains why each directive exists, not just what it does.