Nginx Security Hardening Config
Set your host, root and a few options and get a hardened nginx server block with modern TLS, HSTS, security headers, hidden version number, request limits and rate limiting.
Use the tool
Why this tool exists
A default nginx install works, but it announces its version, serves dotfiles and backup files if they exist, allows every method and sends few security headers. Fixing this means collecting directives from several guides, and it is easy to miss one or to paste an outdated cipher list.
This generator writes a server block that includes the usual hardening in one place: TLS settings, HSTS, a Content-Security-Policy you can edit, request body limits, rate limiting, blocking of hidden and backup files, and a method allow-list. Review each part before production, since a strict CSP or HSTS can break a site that is not ready. Test with nginx -t. The configuration is created in your browser.
How to use it
- Enter the server name and the document root.
- Choose TLS, HSTS and rate limiting options, and enter a Content-Security-Policy and body size limit.
- Set the allowed HTTP methods.
- Copy the block into your nginx configuration, run nginx -t, then reload.
Frequently asked questions
Is it safe to enable HSTS straight away?
HSTS tells browsers to use HTTPS only for the given period, and the browser remembers it. Enable it once your site works fully over HTTPS, and start with a short max-age while you test.
Will the default CSP work for my site?
Probably not unchanged. A strict policy blocks inline scripts and third-party resources until you allow them. Start in report-only mode in a staging copy, and edit the policy to match your pages.
Does hardening guarantee security?
No. It reduces common exposure, but your application, updates and certificates matter just as much. Check your result with a TLS and header scanner after deploying.