502 Bad Gateway
Nginx can't reach the upstream — wrong port, wrong host, or the process isn't running.
Fix: Verify the upstream with `curl http://127.0.0.1:3000` from the same host before reloading Nginx.
Search tools and pages.
Generate a production-ready nginx.conf for reverse proxying with proxy_pass, headers, timeouts, and gzip from a focused form
sidebar • 160x600
Written by Giorgos Kostas. Last reviewed:
Nginx Reverse Proxy Generator builds a focused server block that forwards requests to a single upstream — typically a Node, Python, Go, Rails, or PHP-FPM process listening on `127.0.0.1`.
It pre-fills the headers that broken proxies most often forget — `Host`, `X-Real-IP`, `X-Forwarded-For`, `X-Forwarded-Proto`, `X-Forwarded-Host` — and exposes the timeout dials you'll actually want to change.
server_name = api.example.com proxy_pass = http://127.0.0.1:3000 timeout = 60s forward X-Forwarded-* = on
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
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_read_timeout 60s;
}
}Nginx can't reach the upstream — wrong port, wrong host, or the process isn't running.
Fix: Verify the upstream with `curl http://127.0.0.1:3000` from the same host before reloading Nginx.
Headers are forwarded, but the upstream isn't configured to trust them.
Fix: Enable proxy trust in your framework (e.g. Express `app.set('trust proxy', true)`, Rails `config.action_dispatch.trusted_proxies`).
Default `proxy_read_timeout` is 60s — short for SSE or slow APIs.
Fix: Bump the timeout in this generator (e.g. 300s) and consider streaming endpoints separately.
Drop it into `/etc/nginx/conf.d/<name>.conf` (most distros) or `/etc/nginx/sites-available/<name>` and `ln -s` to `sites-enabled/`. Test with `sudo nginx -t`, then reload with `sudo systemctl reload nginx`.
Nginx uses HTTP/1.0 to upstreams by default, which disables keep-alive and breaks websocket upgrades. Setting `proxy_http_version 1.1` is the universal fix.
If your traffic terminates TLS at this Nginx, switch to the Nginx SSL Config Generator (it shares the same proxy fields and adds the certificate plumbing).
Replace `http://127.0.0.1:3000` with the upstream URL — but be aware that Nginx resolves the hostname once at startup unless you configure a `resolver` directive.
No — for multiple upstream servers with round-robin / least-conn / IP hash, use the Nginx Load Balancer Config Generator.
Without it, Nginx sends the literal upstream IP/port as the `Host` header, which breaks virtual-host routing on the upstream and confuses framework URL helpers.
Pair with the rest of the Nginx generators. You can also browse the full DevOps & Infra category for more options.
Generate an HTTPS-ready nginx.conf with SSL certificate paths, modern protocols, ciphers, HSTS, and HTTP-to-HTTPS redirect
Generate an nginx upstream + load balancer config with round-robin, least_conn, ip_hash, weights, health checks, and keepalive
Generate an nginx config for proxying WebSocket connections with Upgrade and Connection headers and long read timeouts
Generate an nginx.conf for serving a static site with try_files, SPA fallback, gzip, brotli, and aggressive cache headers
Build a Content Security Policy header from per-directive cards with chip-style sources, presets, and a live header + meta-tag preview
Paste response headers to audit HSTS, CSP, CORS, X-Powered-By disclosure, and Set-Cookie flags
Validate docker-compose.yml against the Compose Spec schema with hand-written lints (port collisions, undefined networks, depends_on cycles)
Edit .env files in a key/value table with type detection, masked secrets, duplicate-key warnings, and export to JSON, YAML, shell, or docker-compose
Explore multi-document Kubernetes manifests grouped by kind with a cross-reference graph (Service to Deployment, ConfigMap mounts, Ingress backends)
sudo nginx -t && sudo systemctl reload nginxcontent bottom • up to 300x250