Skip to content

DevOps & Cloud Tools

Nginx Config Generator

Generate Nginx server blocks for proxies and static sites.

nginx config generatorRuns in your browserUpdated 2026-09-22
Options

nginx.conf server block for tlks.io

# Generated with TLKS Nginx Config Generator.
# Save as /etc/nginx/sites-available/tlks.io and enable it with a symlink in sites-enabled/.
# Validate with: nginx -t && systemctl reload nginx

# Redirect the www host to the canonical host.
server {
    listen 80;
    listen [::]:80;
    server_name www.tlks.io;
    return 301 https://tlks.io$request_uri;
}

# Redirect plain HTTP to HTTPS.
server {
    listen 80;
    listen [::]:80;
    server_name tlks.io www.tlks.io;
    return 301 https://$host$request_uri;
}

# Main server block.
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;

    ssl_certificate /etc/letsencrypt/live/tlks.io/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/tlks.io/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers off;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;
    server_name tlks.io www.tlks.io;

    client_max_body_size 10m;

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

    # Do not leak the Nginx version in responses and headers.
    server_tokens off;

    # Required for websockets: both headers must be forwarded together.
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    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;
        proxy_read_timeout 60s;
        proxy_buffering off;
    }

    location ~* \.(?:css|js|woff2?|svg|png|jpg|jpeg|webp|avif|ico)$ {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        expires 30d;
        add_header Cache-Control "public";
        access_log off;
    }

    location = /healthz {
        access_log off;
        return 200 'ok';
        add_header Content-Type text/plain;
    }

    # Deny access to dotfiles such as .git and .env.
    location ~ /\. {
        deny all;
    }
}
Review the output before applying it. Certificates, paths and upstream addresses are placeholders you must replace with values from your own server.

About Nginx Config Generator

Most production Nginx configurations are variations on a small number of patterns, yet writing one from scratch means remembering upstream blocks, proxy header forwarding, gzip settings, TLS protocols and cache behaviour all at once. A forgotten Connection header breaks a websocket; a forgotten host header breaks the backend routing.

This generator produces a complete, commented server block for a reverse proxy or a static site. Choose TLS, compression, caching, websocket support and redirects, and the output arranges the directives in the order Nginx expects.

How it works

  • Choose a mode: reverse proxy to an upstream, or serve static files from a directory.
  • TLS options add the certificate paths, protocol versions and session cache directives.
  • Websocket support adds the Upgrade and Connection headers together, since one without the other does nothing.
  • Compression adds gzip directives for text-based content types.
  • Static asset caching adds an expiry rule for common file extensions.
  • A www redirect emits a second server block that rewrites the host name.
  • The output includes comments explaining each block so you can remove what you do not need.

Input and output

Accepts

Domain, mode, upstream address or document root, TLS choice, and feature toggles.

Produces

A complete Nginx server block with comments, ready to review and place in sites-available.

Privacy

The configuration is assembled in your browser. Certificate paths are placeholders you replace locally.

Nginx Config Generator FAQ

Where does this file go on a Debian or Ubuntu server?

Place it in /etc/nginx/sites-available/, symlink it into sites-enabled/, then run nginx -t to validate and reload the service.

Why do websockets need special headers?

Upgrading a connection requires both Upgrade and Connection headers to be forwarded to the backend. Nginx strips them by default, so the handshake fails with a 400 or a hanging request.

Which proxy headers should I forward?

At minimum Host, X-Real-IP and X-Forwarded-For, plus X-Forwarded-Proto when TLS terminates at Nginx so the backend can build correct absolute URLs.

Does the generated config include rate limiting?

Not by default. Rate limiting requires a limit_req_zone in the http context, which lives outside a single server block, so add it deliberately.