Home / Configs / Servers / nginx reverse proxy config

nginx reverse proxy config: example and generator

Send visitors from port 80 to an app running on port 3000.

For Linux servers running nginx 1.18 or newer (Ubuntu, Debian, Fedora). Paths differ on Windows and macOS.

An nginx reverse proxy sits in front of your app and passes visitors from port 80 to the port your app listens on, such as 3000. Fill in your domain and port below to get a ready config, then follow the steps to turn it on.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Use localhost for local testing
Where your app listens
For example 1m, 50m, 1g
Each visitor address may send this many per second

/etc/nginx/conf.d/myapp.conf
server {
  listen 80;
  server_name example.com;
  client_max_body_size 10m;

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

How this setup works

Diagram: Browser, then nginx, then Your app
Browser (your domain) → nginx (port 80) → Your app (your port)

Step-by-step setup

  1. Start your app so it listens on 127.0.0.1:3000.
  2. Save the config above as /etc/nginx/conf.d/myapp.conf.
  3. Test it: sudo nginx -t.
  4. Apply it: sudo systemctl reload nginx.
  5. Add HTTPS: sudo certbot --nginx -d example.com.

What the important lines mean

Common errors and how to fix them

502 Bad Gateway
nginx cannot reach your app. Check the app is running on port 3000.
bind() to 0.0.0.0:80 failed
Another program uses port 80. Find it with sudo ss -tlnp | grep :80.
nginx -t says unknown directive
A typo or missing semicolon. The error shows the file and line number.

Frequently asked questions

What is a reverse proxy in nginx?
It is a server that receives requests from browsers and forwards them to another server, usually your app on the same machine. Visitors see only nginx, while your app stays on a private port.
How do I fix 502 Bad Gateway in nginx?
A 502 means nginx cannot reach your app. Check that the app is running, that the port in proxy_pass matches the port it listens on, and read /var/log/nginx/error.log for the exact reason.
How do I add HTTPS to this config?
Run sudo certbot --nginx -d your-domain after the config works on port 80. Certbot adds the certificate and the redirect for you.

Written for: nginx 1.26, Ubuntu 24.04 · Updated 2026-10-02

Free tools that help

Fix a problem with this setup

More server configs

See all 41 config generators