Nginx config generator — reverse proxy, static site, SPA or HTTPS redirect

Choose what nginx should do, enter your domain, and the tool writes a server block with an HTTP-to-HTTPS redirect, Let's Encrypt certificate paths, gzip and basic security headers.

Live demo · real result from this tool

site.conf

# /etc/nginx/conf.d/example.com.conf — test with: sudo nginx -t && sudo systemctl reload nginx # Redirect all HTTP traffic to HTTPSserver {    listen 80;    listen [::]:80;    server_name example.com www.example.com;    return 301 https://$host$request_uri;} server {    listen 443 ssl;    listen [::]:443 ssl;    http2 on;    server_name example.com www.example.com;     # Certificates from Let's Encrypt (certbot) — adjust the paths if you use another CA    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_cache shared:SSL:10m;
    ssl_session_timeout 1d;

    client_max_body_size 10m;

    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_types text/plain text/css application/javascript application/json image/svg+xml application/xml;

    # Security headers
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;
    add_header X-Frame-Options "SAMEORIGIN" always;

    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;
    }
}

Uses the http2 directive introduced in nginx 1.25.1 (older versions need listen 443 ssl http2). Get certificates first, e.g. sudo certbot certonly --nginx -d example.com -d www.example.com.

Processed on your device — nothing is uploaded.

How to use the nginx config generator

  1. Choose Use: Reverse proxy to an app, Static website, Single-page app, or HTTP → HTTPS redirect only.
  2. Enter the Domain and tick Also serve www. if needed.
  3. For a proxy, set the App address, such as http://127.0.0.1:3000, and tick WebSocket support if the app uses it. For static sites and SPAs, set the Web root and Long cache for static assets.
  4. Choose HTTPS with Let’s Encrypt certificates, gzip compression, Security headers and Max upload size (MB, 0 = default 1 MB).
  5. Save the file in /etc/nginx/conf.d/, then run sudo nginx -t && sudo systemctl reload nginx.

What it does and when to use it

nginx sits in front of your app or files and answers web requests. A small setup needs an HTTP-to-HTTPS redirect, a server with a certificate, and the right proxy headers for the app behind it. This tool writes those blocks with current syntax.

Use it when you deploy to a VPS or host a built front end. A Docker setup from the Docker Compose generator can mount this file as its nginx config. On Apache hosting, use the .htaccess generator instead, and add a Content-Security-Policy with the CSP header generator. The official nginx documentation covers every directive.

How it works

  • HTTPS on: a port-80 server returns 301 to https://$host$request_uri, and the main server listens on 443 with http2 on;, TLS 1.2 and 1.3, and the Let’s Encrypt paths for your domain.
  • Proxy: proxy_pass plus forwarded headers, so your app sees the real visitor IP and scheme.
  • Static and SPA: root, index index.html, try_files, an optional one-year cache for assets, and a rule that denies dotfiles except .well-known.
  • Security headers: X-Content-Type-Options, Referrer-Policy, X-Frame-Options, plus HSTS when HTTPS is on.

Worked examples

HTTPS reverse proxy (defaults). For example.com with www:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

then the 443 server with client_max_body_size 10m; and proxy_pass http://127.0.0.1:3000;.

SPA over plain HTTP. Domain app.example.org, no www, web root /srv/app/dist, HTTPS off, upload size 0. The block listens on port 80 only, has root /srv/app/dist; and try_files $uri $uri/ /index.html;, and no client_max_body_size line.

WebSocket app on port 8080. App address 127.0.0.1:8080 (the tool adds http://), headers and gzip off. The location adds proxy_set_header Connection "upgrade"; and the matching Upgrade header.

Limits and tips

  • Header inheritance. nginx drops server-level add_header lines inside a location that sets its own. The asset cache block sets Cache-Control, so the tool repeats the security headers there. Do the same in any location you add with its own add_header.
  • HSTS is hard to undo. Browsers remember it for a year; enable it only when HTTPS works on every subdomain.
  • The certbot command in the note uses your domain, plus the www name when that box is ticked.

Frequently asked questions

nginx -t fails with "cannot load certificate". Why?
The HTTPS block points at the Let's Encrypt folder for your domain, and those files exist only after you request a certificate, for example with sudo certbot certonly --nginx -d yourdomain. Get it first, then test again.
My nginx says "unknown directive http2". What now?
The http2 on; directive needs nginx 1.25.1 or later. On older versions, delete that line and change the listen line to listen 443 ssl http2;.
Why does my single-page app show 404 on refresh?
nginx looks for a file named like the URL, such as /settings, and finds none. Single-page app mode falls back to /index.html, and your app's router takes over.
What is the Max upload size for?
It sets client_max_body_size. nginx rejects larger request bodies, such as file uploads, with a 413 error. 0 leaves the line out, so nginx keeps its default of 1 MB.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close