Use an Nginx server block generator by entering one exact domain, an absolute POSIX document root, a cache duration, a deliberate static-404 or SPA fallback, and an optional gzip choice, then review and test the output before deployment.
For a small static site or single-page application, the Nginx Config Generator converts those inputs into a local HTTP fragment intended for review inside a larger Nginx installation. The output remains in your browser; it cannot inspect the target server or install configuration files.
It is a drafting and review aid, not a complete production template, TLS builder, or application configuration generator.

Choose the fallback behavior first
The fallback setting controls what happens when a request does not match a file or directory. Choose it from the site's real routing behavior before generating any directives.
| Behavior | Static 404 | SPA fallback |
|---|---|---|
| Unknown URL | Returns an explicit 404 when no file or directory matches. | Falls back to /index.html so the client-side router can handle the path. |
| Best fit | An ordinary static or content website. | A single-page application with client-side history routing. |
| Error visibility | Broken URLs remain observable as 404 responses. | Missing assets can receive the home shell with status 200 and hide broken URLs. |
Use the static 404 option for a normal content site. Enable SPA fallback only when unknown application paths must reach a client-side router; otherwise it can disguise broken asset URLs and weaken error semantics.
Enter only values the generator can validate
Use precise inputs because each field controls part of the generated server block. Validation prevents configuration-shaped text from being inserted, but it cannot confirm the target server's files, permissions, DNS, or deployment architecture.
| Input | Accepted value | Why it matters |
|---|---|---|
| Domain | One exact domain; scheme-bearing domains are rejected. | Sets one server_name without adding wildcard, alternate www, or regular-expression routing. |
| Document root | An absolute POSIX path made from bounded safe path characters. | Must exist on the target server with suitable ownership and read permissions. |
| Cache duration | An integer from 1 to 365 days. | Sets the asset expires duration and adds Cache-Control: public. |
| Fallback | Static 404 or SPA fallback. | Controls missing-path behavior and whether unknown routes reach /index.html. |
| Gzip | Optional standard gzip filter. | Adds compressed responses and Vary: Accept-Encoding for the selected content types. |
The root validator rejects semicolons, braces, variables, whitespace, and shell-like syntax so pasted input cannot create extra Nginx directives. Passing validation does not prove that the path exists on the target server or that Nginx can read it; confirm those facts on the server.
Version or fingerprint long-lived asset filenames before choosing a high cache duration. Otherwise, visitors may continue receiving stale files after a deployment because their cached copies have not yet expired.
Review the generated HTTP fragment
The result listens on IPv4 and IPv6 port 80 and selects one exact server_name. It does not add a wildcard, alternate www host, or regular expression because those choices affect virtual-host routing and certificate coverage. If several names should serve or redirect, design that behavior explicitly; the generator cannot infer ownership.
For an ordinary static site, location / uses try_files with the requested URI, a directory form, and an explicit 404 fallback. For an SPA, the final fallback becomes /index.html so unknown application paths can reach the client-side router.
A separate case-insensitive asset location covers a small fixed extension list for CSS, JavaScript, common images, icons, and WOFF2 fonts. The selected duration feeds the expires directive, and Cache-Control: public is added. Compare each line with the actual deployment and the official Nginx core module documentation.
Optional gzip enables the standard filter, adds Vary: Accept-Encoding, and lists CSS, JavaScript, JSON, and SVG in gzip_types. HTML is handled by Nginx's gzip behavior without needing to appear in gzip_types. Review this against the installed modules and the official Nginx gzip module documentation. Compression can create side-channel concerns for secrets reflected in compressed responses, and precompressed assets need a different configuration; measure the actual site and security context.
Generate, install, and test the block
- Confirm that the architecture matches. Use the generator for a small static origin whose files Nginx will serve directly. Gather the exact hostname, production document root, intended fallback, and current Nginx include layout. Managed hosting, containers, Kubernetes ingress, and CDNs may require configuration through a different surface.
- Enter the domain and root. Supply one exact domain without a scheme and an absolute POSIX document root. Avoid spaces, braces, semicolons, variables, and other shell-like syntax because those inputs are rejected.
- Set the cache, fallback, and compression choices. Select a duration from 1 to 365 days, choose a real 404 for a conventional site or SPA fallback for client-routed paths, and enable gzip only after considering the content types and response-security implications.
- Generate and inspect the local output. Copy the block into your configuration workflow and review every directive against the installed Nginx modules, deployment paths, actual files, and intended cache strategy. Do not treat the fragment as a complete production baseline.
- Back up the active configuration. Save the current configuration before making changes and record the active include chain. This gives you a known recovery point and shows where the reviewed fragment belongs.
- Place the fragment in the correct context. Follow the recorded include chain and the conventions of the target installation. Check that the new block does not duplicate a server block that is already active.
- Validate before reloading. Run nginx -t against the full configuration. If it fails, correct the problem and do not reload. A successful test validates syntax and referenced configuration, but not file permissions, DNS, application routing, or certificate behavior. Before reloading, test representative file paths, 404 handling, and the chosen fallback in a safe staging environment.
- Reload and verify live behavior. After the pre-reload checks pass, reload according to the platform's procedure rather than abruptly stopping the service, and keep a recovery shell open. Repeat representative requests against the live endpoint. If those requests fail, restore the backup and inspect the error logs.
Account for TLS and omitted application features
The fragment deliberately omits PHP and FastCGI, reverse proxying, WebSockets, uploads, authentication, rate limits, custom errors, MIME include paths, logging, and security headers. It is a static-site fragment, not a production baseline for every application. Add only directives required by the real architecture and official module documentation.
TLS is excluded because certificate paths, renewal tooling, supported protocols, redirects, proxy or CDN topology, and HSTS policy depend on deployment-specific evidence. Inventing certificate locations would create false confidence. Configure HTTPS through the hosting platform or a reviewed server procedure, then test HTTP-to-HTTPS behavior separately.
Match the tool to the deployment model
Use this generator when the problem really is a small static origin and you control the Nginx configuration. For managed hosting, containers, Kubernetes ingress, or a CDN, the correct configuration surface may be elsewhere. Follow the platform's documented configuration process instead of forcing a generated fragment into an unrelated system.
The generator cannot infer multi-domain routing, certificate coverage, backend settings, or security policy. Add those requirements separately and test each layer. The most maintainable result is the smallest reviewed configuration that matches the available deployment evidence.
A generated server block is therefore not a file to paste without review. It becomes deployable only after the target paths, modules, include chain, fallback behavior, cache strategy, and live responses have all been checked.
If you're weighing options, Nginx Config Generator: From Inputs to Live Tests covers this in detail.
If you're weighing options, Explaining htaccess to Nginx Conversion to Someone Else covers this in detail.