Advertisement
Guide
About the Nginx Config Generator
nginx reads its site settings from server blocks. Each block says which ports and host names it answers, and its location blocks decide what happens to each request: serve a file, fall back to index.html, pass it to PHP-FPM, or proxy it to an app running on another port.
Pick what your site is, fill in the domain, and the generator writes the whole file, including the separate blocks that redirect plain HTTP and the non-canonical host.
Why a single-page app needs try_files
React Router, Vue Router and similar libraries handle URLs like /settings in the browser, but there is no settings file on disk. Without a fallback, a reload on that page returns 404. try_files $uri $uri/ /index.html serves the file if it exists and the app shell otherwise.
Proxy headers your app needs
Behind a proxy, your app sees every request as coming from 127.0.0.1 over HTTP. The X-Forwarded-For and X-Forwarded-Proto headers pass on the real client address and scheme, so redirects, secure cookies and rate limits behave correctly. Tell your framework to trust the proxy (for example app.set('trust proxy', 1) in Express).
How to use it
- 1Pick a preset or choose what nginx serves.
- 2Enter your domain and how www should be handled.
- 3Choose HTTPS and the performance options you want.
- 4Download the .conf, test it with nginx -t, and reload.
Frequently asked questions
Where do I put the nginx config file?
On Debian and Ubuntu, in /etc/nginx/sites-available/, linked into /etc/nginx/sites-enabled/. On other systems, in /etc/nginx/conf.d/ with a .conf extension.
How do I test the config before reloading?
Run sudo nginx -t. It checks syntax and file paths without touching the running server. If it passes, sudo systemctl reload nginx applies the change with no downtime.
Why does my WebSocket connection fail behind nginx?
nginx does not forward the Upgrade and Connection headers by default. Tick WebSocket support to add them, along with HTTP/1.1 and a longer read timeout.
How do I get a free SSL certificate?
Install Certbot and run certbot certonly --nginx -d yourdomain.com. The Let’s Encrypt option uses the paths Certbot writes, and Certbot renews the certificate automatically.
What does client_max_body_size do?
It caps the size of a request body. The default is 1 MB, so larger file uploads fail with 413 Request Entity Too Large until you raise it.
Is the http2 directive right for my nginx version?
http2 on; was added in nginx 1.25.1. On older versions, remove that line and write listen 443 ssl http2; instead.
