How to use
- Pick the purpose: a reverse proxy in front of an app server, static files, an SPA (React or Vue build output) or PHP-FPM.
- Enter your domains separated by spaces. The first is the canonical one and is used for the default certificate path and the file name.
- For a proxy, enter the app server address (for example
http://127.0.0.1:3000); for the others, enter the web root path. - Turn options such as HTTPS, gzip and security headers on or off. Copy the result or download it as
domain.conf, place it in/etc/nginx/conf.d/, check it withsudo nginx -tand apply it withsudo systemctl reload nginx.
What each option generates
| Option | Generated config |
|---|---|
| HTTPS | listen 443 ssl;, certificate and key paths, ssl_protocols TLSv1.2 TLSv1.3;, session cache |
| HTTP redirect | a port 80 server with return 301 https://$host$request_uri; |
| HTTP/2 | http2 on; (syntax for nginx 1.25.1 and newer) |
| HSTS | Strict-Transport-Security "max-age=31536000" (one year) |
| gzip | gzip on; plus MIME types for text, JSON, JS, SVG and more |
| Security headers | X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy |
| WebSocket | Upgrade and Connection headers with map $http_upgrade $connection_upgrade |
| Static cache | expires 30d; for css, js, image and font extensions |
| Dotfile blocking | rejects requests for .git, .env and other dotfiles but allows .well-known |
| www handling | the non-canonical server block returns a 301 to the canonical domain |
Example structure
With the defaults (reverse proxy, HTTPS, domains example.com www.example.com) you get two server blocks. The first listens on port 80 and sends every request to https://$host$request_uri. The second listens on 443, loads the certificate, and passes proxy_pass http://127.0.0.1:3000; along with the Host, X-Real-IP, X-Forwarded-For and X-Forwarded-Proto headers. If you leave the certificate paths empty, the Let’s Encrypt default /etc/letsencrypt/live/example.com/fullchain.pem is used.
Things to know
- The certificate comes first. The 443 block makes
nginx -tfail while the certificate files are missing. The commands below include acertbot certonlyexample. For the webroot method, turn on “Open the webroot path” and apply the port 80 block first. - add_header inheritance: if a child
locationhas even oneadd_header, everyadd_headerfrom the parent server block is ignored there. When you add headers in alocation, repeat the security headers inside it. - Path in proxy_pass: if the address ends with a path such as
/api/, the matched part of the request path is replaced by it. Without a path, the original request path is passed through. - HSTS: once on, browsers use HTTPS only for a year. Turn it on after confirming that HTTPS and certificate renewal work reliably.
- WebSocket map: if another config file already defines
$connection_upgrade, nginx reports a duplicate. In that case delete the generatedmapblock. - Domains and paths accept only safe characters such as letters, digits,
.,-and/. A semicolon or brace is not used and is reported instead. - Review the generated config before using it on a production server. Rate limiting, proxy caching and log formats are not included.
- If you run containers, use the Docker Compose Generator and the Dockerfile Generator; for port policy see the Firewall Rule Generator. Status code meanings are in HTTP Status Codes, crawler rules in the robots.txt Generator, and subnet math in the IP Subnet Calculator.
Frequently asked questions
Where do I put the config file?
It depends on the distribution. Debian, Ubuntu and most Docker images read /etc/nginx/conf.d/*.conf. If you use the Debian-style sites-available and sites-enabled, put the same content in sites-available and create a link.
What should I do about 502 Bad Gateway?
nginx could not connect to the app at the proxy_pass address. Check that the app is running, that the address and port are right, and in Docker whether you need the service name instead of 127.0.0.1. The error log is /var/log/nginx/error.log.
How do I get a certificate?
certbot from Let’s Encrypt is the usual way. This tool shows a certbot certonly example. Check issuance and automatic renewal for your own server setup.
Why do static files return 404?
Check the root path and that the nginx user (usually www-data) can read the folder. For an SPA, choose the SPA purpose so refreshes fall back to index.html.
Is my input sent to a server?
No. The config is generated in your browser only.
Your input is processed in this browser and never sent to a server.