Report

Help us improve this tool

Nginx Config Generator

Generate a production ready Nginx server block from a simple form. Configure static sites, reverse proxies, HTTPS, redirects, gzip, caching, and security headers, then copy or download the config.

O M T

What This Nginx Config Generator Does

Nginx configuration is block based, which makes it powerful and easy to get subtly wrong. A single misplaced semicolon or a conflicting server block can take a site offline, and the error messages rarely point at the real problem. This generator builds a complete server block from a short form so the structure is correct from the start, with the directives that most deployments need already wired together.

The output covers three common setups: a static site, a single page app with client-side routing, and a reverse proxy in front of an application server. You can layer HTTPS, HTTP to HTTPS redirects, www to non-www redirects, gzip compression, and static asset caching on top. The config on the right updates as you type, and copying it produces a drop-in file for /etc/nginx/sites-available/ or /etc/nginx/conf.d/.

How to Use It

  1. Pick the site type. Static sites serve files from a root directory, SPAs fall back to index.html for unknown paths, and reverse proxies forward traffic to a backend application.
  2. Enter your domain as the server name, for example example.com. This is the apex domain without www; the www redirect option handles the other host name for you.
  3. Set the listen port. Port 80 is the default; change it only when nginx runs behind another proxy or on a custom port.
  4. Set the root directory for static sites and SPAs, or the proxy pass address such as http://127.0.0.1:3000 for reverse proxies.
  5. Enable SSL to add the certificate paths, TLS settings, and HTTPS listener, then decide whether to redirect HTTP traffic and the www host name.
  6. Copy the generated config, paste it into your nginx configuration, and reload nginx after testing the file with nginx -t.

Static Sites, SPAs, and Reverse Proxies

A static site block points nginx at a directory and serves files directly. The generated try_files $uri $uri/ =404; directive returns a real 404 for missing paths instead of leaking directory listings, which is the behavior most static hosts expect.

A single page app needs a fallback so that routes like /dashboard/settings reach the application instead of a 404. The generator swaps the 404 fallback for try_files $uri /index.html;, which serves the app shell for any path that does not match a real file. This is required for React, Vue, and Svelte apps with client-side routing.

A reverse proxy forwards requests to a backend such as a Node.js, Python, or Go process. The generated location block includes the standard proxy headers: Host, X-Real-IP, X-Forwarded-For, and X-Forwarded-Proto, plus the Upgrade and Connection headers that keep WebSocket connections alive. Without the forwarded headers, your application sees nginx's address instead of the visitor's.

HTTPS and Redirects

Enabling SSL produces a site that listens on 443 with modern TLS settings: TLSv1.2 and TLSv1.3, a shared session cache, and server cipher preference turned off in favor of the client's order. The certificate and key paths default to the Let's Encrypt layout, so an existing certbot installation usually works without edits.

The HTTP to HTTPS redirect is generated as a separate port 80 server block that returns a 301 to the matching HTTPS URL. The www redirect follows the same idea from the other direction: requests to www.example.com are permanently redirected to the apex domain. When both options are active, the generator combines them so a request to http://www.example.com reaches https://example.com in one hop instead of two.

Compression and Caching

Gzip is enabled with sensible defaults: compression level 5, a 256 byte minimum length so tiny responses are skipped, and a type list that covers HTML, CSS, JavaScript, JSON, XML, and SVG. Compression is proxied traffic aware and sets Vary: Accept-Encoding, which keeps caches from serving the wrong encoding to the wrong client.

Static asset caching adds a location block for common asset extensions that sets a 30 day expiry and a Cache-Control: public, immutable header, so browsers stop revalidating images, fonts, and versioned bundles. Pair it with hashed file names from your build tool and the cache can stay aggressive without risking stale files.

After You Generate the File

Always run nginx -t before reloading. The test command parses the full configuration and reports the exact file and line if something is wrong. Then reload with systemctl reload nginx for a zero downtime update. If DNS is not pointing at the server yet, check the records first with the DNS Lookup tool, and if you need to inspect or reshape URLs before writing rewrite rules, the URL Parser breaks any link into its component parts.

Running Apache instead? The .htaccess Generator covers the same redirects, caching, and compression rules for Apache. When you add headers, keep a status code reference handy with HTTP Status Codes, and harden browser behavior with the Content Security Policy Generator.

Frequently Asked Questions

Does this generator handle SSL certificates?

It generates the ssl_certificate, ssl_certificate_key, and TLS protocol directives, but you still need a certificate. Let's Encrypt with certbot is the usual choice, and the default paths in the form match the certbot output layout.

Where do I put the generated file?

On Debian and Ubuntu, sites usually live in /etc/nginx/sites-available/example.com with a symlink in /etc/nginx/sites-enabled/. On RHEL based systems, drop it in /etc/nginx/conf.d/example.com.conf. Either way, run nginx -t before reloading.

Why do I need the proxy headers for a reverse proxy?

Without X-Real-IP and X-Forwarded-For, your application sees every request as coming from nginx itself, which breaks logging, rate limiting, and geolocation. X-Forwarded-Proto tells the app whether the original request was HTTP or HTTPS so it can generate correct links.

Is the generated configuration safe to use in production?

The template follows widely used production patterns: strict try_files fallbacks, modern TLS settings, and gzip tuned for text responses. Treat it as a solid starting point, review it against your own requirements, and test with nginx -t before applying it.

Can I use this for subdomains?

Yes. Enter the full host name such as api.example.com as the server name. The www redirect option only makes sense for apex domains, so leave it off for subdomains.

What does the www to non-www redirect actually do?

It creates a separate server block for www.yourdomain that answers with a permanent 301 redirect to the apex domain. Search engines then treat both host names as one site instead of two duplicates.

My SPA shows a blank page after deploying. What should I check?

Make sure the root directory points at the folder containing index.html, and that the single page app type is selected so unknown paths fall back to the app shell. A wrong root is the most common cause of blank pages behind nginx.