Free tools / nginx reverse proxy generator

Nginx reverse proxy config generator

Put a Node, Python, Go or any other local app behind nginx with HTTPS from Let's Encrypt. The generator writes the server block for /etc/nginx/sites-available, with an HTTP only variant for the first run so nginx -t passes before certbot has issued the certificate. The output works with nginx 1.18 and newer, which covers Ubuntu 22.04 and Debian 12.

Everything runs in your browser. Nothing you type is sent to a server or stored.

Stage

Site

Options

The HTTPS blocks read the certificate from certbot's standard paths in /etc/letsencrypt/live/example.com/. If the certificate does not exist yet, nginx -t fails. Use the before certificate stage first.
/etc/nginx/sites-available/example.com
# /etc/nginx/sites-available/example.com
# Generated at nocthost.com/tools/nginx-reverse-proxy-generator
# Certificate: certbot's standard paths under /etc/letsencrypt/live/example.com/
# "listen ... ssl http2" works on every nginx version; 1.25.1 and newer print a notice suggesting "http2 on;".

# WebSocket: send Connection: upgrade only when the client asks for it
map $http_upgrade $connection_upgrade_example_com {
    default upgrade;
    ''      close;
}

# HTTP: send everything to HTTPS
server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    location / {
        return 301 https://$host$request_uri;
    }
}

# HTTPS: proxy to the app
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_session_timeout 1d;
    ssl_session_tickets off;

    client_max_body_size 10m;

    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 5;
    gzip_min_length 256;
    gzip_types text/plain text/css text/xml application/json application/javascript application/xml application/rss+xml image/svg+xml;

    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_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade_example_com;
        proxy_read_timeout 1h;
    }
}
Commands
# 1. Install nginx and certbot
sudo apt update && sudo apt install -y nginx certbot python3-certbot-nginx

# 2. Save the config and enable the site
sudo nano /etc/nginx/sites-available/example.com
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

# 3. Test the syntax and reload
sudo nginx -t
sudo systemctl reload nginx

# The files in /etc/letsencrypt/live/example.com/ must exist before nginx -t passes.
# No certificate yet? Use the before certificate variant first.

# 4. Check that automatic renewal works
sudo certbot renew --dry-run

How to use

  1. Point the DNS records of every domain to the server and open ports 80 and 443 in the firewall.
  2. Start with the before certificate stage. Save the file, enable the site, run sudo nginx -t and reload nginx.
  3. Run the certbot command from the output. It uses the nginx plugin to prove you control the domain and stores the certificate in /etc/letsencrypt/live/.
  4. Switch the generator to the HTTPS stage, replace the file with the new output, then run sudo nginx -t and reload again.
  5. Open the site over HTTPS, and check renewal with sudo certbot renew --dry-run.

Frequently asked questions

Why does nginx -t fail with the HTTPS config?

The HTTPS blocks point to /etc/letsencrypt/live/<domain>/fullchain.pem and privkey.pem, which only exist after certbot has issued the certificate. Use the before certificate stage first, get the certificate, then switch to HTTPS.

Will certificate renewal keep working with the redirect?

Yes. The redirect to HTTPS sits inside location /, so the exact location certbot adds for /.well-known/acme-challenge/ during renewal takes priority. certbot installs a timer that renews certificates automatically before they expire.

Why are the map and limit_req_zone names tied to the domain?

Both live in the http context, which every site in sites-enabled shares. Two files defining the same name make nginx -t fail, so the names include the domain and several generated sites can run side by side.

My app sees every request coming from 127.0.0.1. How do I get the real IP?

nginx passes the client address in the X-Real-IP and X-Forwarded-For headers. Tell your framework to trust the proxy, for example app.set('trust proxy', 1) in Express or ProxyHeadersMiddleware in Uvicorn, and it will read the real address from them.

Further reading

More free tools

Need a server to run it on? Deploy a Debian VPS