Skip to content

Using Nginx as Reverse Proxy

In many deployments:

  • Nginx handles incoming HTTP/HTTPS traffic
  • Gunicorn runs your Flask app
  • HTTPS termination (TLS)
  • better performance for static files
  • request buffering
  • security headers
  • reverse proxy routing
diagram Diagram mermaid
nginx
server {
    listen 80;
    server_name 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;
    }
}

Often you configure Nginx to serve /static/ directly.

That reduces load on Gunicorn.

If you build absolute URLs, make sure Flask knows it’s behind HTTPS.

Forwarded headers (X-Forwarded-Proto) and proper proxy settings matter.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading