Nginx config generator

Answer a few questions to get a clean Nginx server block for a reverse proxy, static site, single-page app or PHP site, with HTTPS, redirects, compression and security headers.

example.com.conf

How to use the nginx config generator

  1. Choose the site type and enter your domain. Separate several domains with spaces.
  2. Tick the options you want. The config updates as you change them.
  3. Click Copy or Download, save the file in your Nginx config folder, then run nginx -t and reload.

Where the file goes

SetupFolderThen
Debian and Ubuntu/etc/nginx/sites-available/Link it into sites-enabled/
RHEL, Fedora, Alpine, official Docker image/etc/nginx/conf.d/The file name must end in .conf
SWAG (linuxserver.io)/config/nginx/proxy-confs/Name it app.subdomain.conf

Always test before reloading:

sudo nginx -t && sudo systemctl reload nginx

What the options do

  • Redirect HTTP to HTTPS adds a second server block on port 80 that sends every visitor to the secure address with a 301 redirect.
  • HSTS tells browsers to use HTTPS only for the next year. Turn it on once HTTPS works on every subdomain you care about, because it is hard to undo.
  • WebSocket support passes the Upgrade and Connection headers, which apps with live updates need.
  • Cache static files lets browsers keep images, fonts, CSS and JavaScript for 30 days.
  • Security headers adds X-Content-Type-Options, X-Frame-Options and Referrer-Policy.
  • Block hidden files refuses requests for files such as .env and .git, while still allowing .well-known for certificate renewals.

Getting a free certificate

With Certbot installed, one command gets a Let's Encrypt certificate and stores it at the paths this generator uses:

sudo certbot certonly --nginx -d example.com -d www.example.com

Running the app in a container? Build the stack with the Docker Compose generator. To check a certificate you already have, use the SSL certificate decoder.

Private by design

This tool runs entirely in your web browser. Nothing you type or paste is sent to a server, logged or stored, so it is safe to use with internal addresses, configuration files and other work data. There is no sign-up and it keeps working offline once the page has loaded.

Frequently asked questions

How do I set up Nginx as a reverse proxy?

Choose “Reverse proxy to an app”, enter your domain and the address your app listens on, such as http://127.0.0.1:3000, and save the generated file in your Nginx config folder.

How do I redirect HTTP to HTTPS in Nginx?

Add a server block that listens on port 80 and returns 301 https://$host$request_uri. The generator adds it when the redirect box is ticked.

Why does my single-page app show 404 on refresh?

The server looks for a file matching the address. The single-page app option adds try_files $uri $uri/ /index.html, which sends unknown paths to your app.

How do I test an Nginx config?

Run sudo nginx -t. It reports syntax errors with the file and line number without touching the running server.