🔧 Nginx Config Generator
Generate nginx server block config: reverse proxy, SSL, gzip, caching, security headers
Save as /etc/nginx/sites-available/example.com, symlink to sites-enabled/, then run nginx -t and systemctl reload nginx.
About this tool
An Nginx server block (also called a virtual host) tells Nginx how to handle requests for a specific domain — where files live, what to proxy, whether to terminate TLS, which headers to set. Writing one from scratch every time you deploy is tedious and a common source of mistakes (forgotten security headers, broken WebSocket upgrades, missing client-route rewrites). This generator produces a complete, commented server block from a short form.
Pick a server type, enter your domain, toggle the options you need, and a ready-to-paste config appears. Examples: a static site for example.com rooted at /var/www/html produces a block with try_files $uri $uri/ =404 and 1-year asset caching; a reverse proxy in front of a Node app on port 3000 produces a location / with proxy_pass and full header forwarding (including Upgrade for WebSockets); a PHP-FPM setup emits a correct fastcgi_pass block for WordPress or Laravel.
The HTTPS option wires in Let's Encrypt certificate paths and adds an HTTP-to-HTTPS redirect server block. After generating, run nginx -t to validate the config before reloading.
FAQ
Where do I put this config file? ›
On Debian/Ubuntu, save it to /etc/nginx/sites-available/example.com, then create a symlink with sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/. On CentOS/RHEL, use /etc/nginx/conf.d/example.com.conf instead. Reload Nginx afterwards.
How do I get the Let's Encrypt certificates? ›
Install certbot and run sudo certbot --nginx -d example.com -d www.example.com. Certbot provisions the certificate, edits your Nginx config, and sets up automatic renewal. The HTTPS option in this generator pre-fills the certificate paths that certbot will use.
Why does the proxy block include Upgrade headers? ›
Those headers let Nginx forward WebSocket connections, which require an HTTP Upgrade handshake. Without proxy_set_header Upgrade $http_upgrade and Connection "upgrade", real-time features (chat, live data, HMR in dev) silently break when the app sits behind a reverse proxy.
My SPA shows 404 on refresh — why? ›
Client-side routes only exist in the browser, so refreshing /dashboard asks Nginx for a file that does not exist. The SPA server type uses try_files $uri $uri/ /index.html to fall back to index.html, letting the app's router handle the path. Make sure the fallback line is present.
Can I add custom directives the generator doesn't include? ›
Yes — the output is plain text. Treat it as a correct starting point and edit it by hand for anything bespoke (rate limiting, basic auth, custom log formats, geo blocking). Always re-run nginx -t after editing.