An Nginx Config Generator alternative for static sites produces a validated HTTP server block from a single domain, absolute document root, cache duration, and optional gzip settings—without generating unsafe TLS assumptions or application backends. Unlike broad configuration tools that attempt to cover every use case, this tool focuses on a narrow, auditable fragment for static files or single-page applications (SPAs). It enforces exact server names, rejects injection-shaped inputs, and outputs a block that listens on IPv4 and IPv6 port 80 only. This approach ensures the configuration matches deployment evidence while avoiding virtual-host routing or certificate coverage guesses that could break production.
Static sites and SPAs often share similar Nginx requirements: a fixed document root, predictable asset caching, and fallback behavior for missing files. However, mixing these behaviors can create problems. For example, enabling SPA fallback on a content site may return a 200 status for broken URLs, hiding errors from monitoring tools. The generator addresses this by requiring deliberate choices—static 404 or SPA fallback—so the output aligns with the site’s actual architecture. Cache durations (1 to 365 days) apply only to a bounded list of extensions (CSS, JavaScript, images, fonts), but long durations demand versioned or fingerprinted assets to prevent stale files after deployments. Optional gzip compression adds Vary: Accept-Encoding and covers standard types, but HTML is handled by Nginx’s default behavior to avoid redundancy.
The tool’s limits are intentional. It excludes TLS, PHP, FastCGI, reverse proxies, and security headers because these depend on deployment-specific details like certificate paths, renewal tooling, or proxy topology. Inventing these would create false confidence, so the generator leaves them to reviewed server procedures. Similarly, it omits wildcard domains, alternate www hosts, or regular expressions for server_name, as these affect routing and certificate coverage. If multiple names should serve or redirect, you must design that behavior explicitly rather than relying on a generator to infer ownership. The document root must be an absolute POSIX path with safe characters; the browser cannot verify its existence or permissions on the target server, so manual checks are still required. Try the Nginx Config Generator to do this in your browser.

When to Use This Tool Instead of Broad Generators
Broad Nginx configuration generators often produce bloated or unsafe blocks by making assumptions about TLS, application backends, or wildcard domains. These assumptions can lead to misconfigurations, such as incorrect certificate paths or unintended virtual-host routing. The Nginx Config Generator avoids these pitfalls by focusing on a single static-site or SPA use case. It rejects unsafe inputs like semicolons, braces, or variables, which could create extra directives or syntax errors. The output is a minimal, review-ready block that matches the current deployment’s needs without guessing at future requirements.
For example, if your site is a static blog or a React/Vue SPA, the generator’s bounded approach ensures the configuration is both correct and maintainable. It does not add unnecessary directives for PHP, FastCGI, or reverse proxies, which would complicate debugging if they’re unused. The tool also enforces exact server_name matching, preventing conflicts with other virtual hosts on the same server. If you need HTTPS, you must configure it separately through your hosting platform or a reviewed procedure, as certificate paths and renewal tooling vary across deployments.
Use this tool when your goal is a small, auditable Nginx block for a static site or SPA. Avoid it if you need TLS, application backends, or complex routing rules—those require manual configuration or a more specialized tool. For managed hosting, containers, or CDN-based deployments, the correct configuration surface may lie elsewhere, such as a Kubernetes ingress or a platform-specific dashboard.
How to Generate a Static-Site Nginx Config
Enter the exact domain and document root. Provide one domain (e.g., example.com) and an absolute POSIX path (e.g., /var/www/example.com/html). The tool rejects scheme-bearing domains (e.g., https://example.com) or unsafe path characters like semicolons or braces. The path must exist on the target server with correct ownership and read permissions, but the browser cannot verify this—you must check manually.
Set the cache duration and fallback behavior. Choose a cache duration between 1 and 365 days for static assets (CSS, JavaScript, images, fonts). For a static site, select 404 as the fallback. For an SPA, enable SPA fallback to route unknown paths to /index.html. Do not enable SPA fallback for content sites, as it can hide broken URLs.
Enable gzip (optional). If your site serves compressible assets, enable gzip. The tool adds Vary: Accept-Encoding and lists standard types (CSS, JavaScript, JSON, SVG). HTML is handled by Nginx’s default gzip behavior, so it does not appear in gzip_types. Measure your site’s compression needs, as gzip can create side-channel risks for secrets in responses.
Generate and review the block. Click Generate to produce the server block. The tool validates every directive against installed Nginx modules, deployment paths, and cache strategy. Review the output for correctness, especially the root, try_files, and expires directives. The block listens on IPv4 and IPv6 port 80 and uses an exact server_name—no wildcards or regex.
Back up your active configuration. Before deploying, save the current Nginx configuration and record the active include chain. This ensures you can restore the previous state if the new block causes issues. Place the generated fragment in the correct context within your Nginx installation, such as /etc/nginx/sites-available/example.com.
Test syntax and live requests. Run nginx -t to validate the full configuration. A successful syntax test does not guarantee file permissions, DNS, or application routing, so request representative paths (e.g., /, /about, /nonexistent) to verify behavior. If the test fails, do not reload Nginx—restore the backup and inspect error logs.
Reload Nginx and monitor. If the syntax test passes and live requests succeed, reload Nginx using the platform’s procedure (e.g., systemctl reload nginx). Keep a recovery shell open in case of issues. If requests fail after reload, restore the backup immediately and check error logs for permissions, paths, or routing problems.
Key Directives in the Generated Block
| Directive | Purpose | Example Value | Notes |
|---|---|---|---|
| listen | Defines the IP and port for the server block. | 80; listen [::]:80; | Listens on IPv4 and IPv6 port 80 only. No TLS. |
| server_name | Matches the exact domain for this block. | example.com; | No wildcards or regex. Only one domain per block. |
| root | Sets the absolute document root path. | /var/www/example.com/html; | Must be an absolute POSIX path with safe characters. |
| try_files | Defines fallback behavior for missing files. | $uri $uri/ =404; (static) or $uri $uri/ /index.html; (SPA) | SPA fallback should only be used for client-side routing. |
| expires | Sets cache duration for static assets. | 30d; | Applies to a fixed list of extensions (CSS, JS, images, fonts). |
| gzip | Enables compression for supported types. | on; | Adds Vary: Accept-Encoding and covers standard types. |
Pitfalls to Watch For
Even with a validated generator, small oversights can break your Nginx configuration. Here are the most frequent issues and how to prevent them:
Assuming the document root exists. The generator validates the path format but cannot check its existence or permissions on the target server. Always verify the path manually and ensure the Nginx worker process (e.g., www-data) has read access. Missing permissions will cause 403 errors, even if the syntax test passes.
Enabling SPA fallback for content sites. SPA fallback routes unknown paths to /index.html, which can hide broken URLs and return 200 statuses for missing resources. Use this only for client-side routing (e.g., React, Vue, Angular). For static sites, preserve a real 404 to maintain error semantics and SEO.
Using long cache durations without asset versioning. The generator allows cache durations up to 365 days, but long durations can serve stale files after deployments. Always fingerprint or version assets (e.g., styles.v2.css) before using high durations. Without versioning, visitors may see outdated content until their cache expires.
Skipping live request testing. A successful nginx -t test validates syntax and file references, but it cannot verify DNS, file permissions, or application routing. Always request representative paths (e.g., /, /about, /nonexistent) after reload to confirm the site behaves as expected.
Ignoring the include chain. The generated block must be placed in the correct context within your Nginx installation. Missing or misplaced include directives can prevent the block from loading. Record the active include chain before deploying and ensure the new file is referenced in the main configuration (e.g., /etc/nginx/nginx.conf).
Assuming TLS is included. The generator deliberately excludes TLS to avoid unsafe assumptions about certificate paths, renewal tooling, or proxy topology. Configure HTTPS separately through your hosting platform or a reviewed server procedure, then test HTTP-to-HTTPS redirects and HSTS policy.
For more details on deploying Nginx configurations safely, see our guide on how to get an Nginx config file you can actually deploy.
Alternatives for Advanced Use Cases
The Nginx Config Generator is designed for static sites and SPAs, but other tools or manual approaches may suit advanced needs:
Broad Nginx generators. Tools like nginxconfig.io (external) cover TLS, application backends, and wildcard domains, but they make assumptions that may not match your deployment. Use these only if you need features outside the generator’s scope and are prepared to review the output thoroughly.
Manual configuration. For complex setups (e.g., reverse proxies, WebSockets, authentication), write the configuration manually using the official Nginx core module documentation. This ensures every directive aligns with your architecture and avoids bloated or unsafe blocks.
Managed hosting or CDNs. Platforms like Vercel, Netlify, or Cloudflare handle Nginx configuration automatically. For these, the correct configuration surface may be a dashboard or CLI tool rather than a manual block. Check your provider’s documentation for static-site or SPA-specific guides.
Kubernetes ingress. If you’re deploying in Kubernetes, use an ingress controller (e.g., Nginx Ingress, Traefik) instead of manual Nginx blocks. Ingress resources define routing rules, TLS, and backends in a declarative format, reducing the need for handwritten configurations.
For converting Apache .htaccess files to Nginx, our htaccess to Nginx converter translates a narrow subset of directives while surfacing unsupported rules. This is useful for migrating legacy configurations but requires manual review for complex setups.