A reverse proxy sits in front of your application and forwards requests to it. Nginx is the most popular choice, and it's what powers most production web apps.

Why use one

  • Terminate HTTPS in one place.
  • Serve static files efficiently.
  • Buffer slow clients so your app server isn't tied up.
  • Load-balance across multiple app instances.

Basic proxy config

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        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;
    }
}

Add HTTPS

sudo certbot --nginx -d app.example.com

Load balancing

upstream app { server 127.0.0.1:8000; server 127.0.0.1:8001; }

Point proxy_pass at http://app and Nginx spreads traffic across both. Test with nginx -t and reload — you now have a production-grade front end.