Skip to main content
Back to Dev generators

Dev

Nginx Config Snippet Generator

Nginx configuration mistakes are silent in the wrong way — the server starts, traffic flows, but a missing header means your app logs the wrong client IP, a missing try_files means SPA routes return 404 on refresh, and a missing redirect means HTTP traffic never reaches HTTPS. Each pattern this generator produces includes the directives it actually needs. One input controls the output: the Snippet dropdown — Reverse proxy, Static site, HTTPS redirect, or SPA fallback. The reverse proxy block proxies to 127.0.0.1:3000 with the four forwarding headers. The static site block serves files with try_files and adds 30-day cache headers. The HTTPS redirect returns a 301. The SPA fallback uses try_files with /index.html as the final fallback. Drop the block into a sites-available config, update server_name and paths, then run nginx -t to validate before reloading.

Read the complete guide — 4 min read

How to use

  1. Choose your options above
  2. Click Generate
  3. Copy your result

Detailed instructions

  1. Pick the snippet you need.
  2. Click Generate to produce the server block.
  3. Edit server_name and paths to match your setup.
  4. Run nginx -t, then reload nginx.

Use Cases

  • Setting up a reverse proxy to an app server
  • Serving a static site with sensible caching
  • Redirecting all HTTP traffic to HTTPS
  • Adding client-side routing fallback for an SPA
  • Recalling the proxy headers nginx must forward

Tips

  • Always run nginx -t before reloading to catch typos.
  • Terminate TLS with the HTTPS redirect plus a 443 server block.
  • Set long cache headers on hashed static assets.
  • Keep one server block per file in sites-available.

FAQ

which snippet patterns are available

Four: a reverse proxy (with forwarding headers for Host, X-Real-IP, X-Forwarded-For, and X-Forwarded-Proto), a static site (with try_files and long cache headers for static assets), an HTTPS redirect (a 301 from HTTP to HTTPS), and an SPA fallback (try_files with /index.html as the final fallback).

why does the reverse proxy include the X-Forwarded headers

Without these headers, the upstream app sees nginx as the client. X-Forwarded-For carries the original client IP, X-Real-IP provides a single clean IP value, and X-Forwarded-Proto tells the app whether the original request was HTTP or HTTPS — important for redirect logic and security rules.

what does the SPA fallback try_files line do

It serves the requested file if it exists, or the directory index if present, otherwise falls back to /index.html. That fallback lets the single-page app's router handle client-side routes on a hard refresh — without it a direct URL returns a 404.

how do I safely test an nginx config change

Run nginx -t to validate the syntax before applying. Then use nginx -s reload or systemctl reload nginx to apply without dropping existing connections. A syntax error found by nginx -t will never reach a live server.

You might also like

Popular tools from other categories that share themes with this one.

Try these next

More free tools from other corners of the catalog, picked by shared themes.