Standard

nginx Config Snippet Generator

Generate ready-to-paste nginx server {} block snippets for common tasks — the nginx counterpart to our .htaccess Snippet Generator for Apache.


    
    

Advertisement

About this tool

Pick a task and fill in your details. Snippets marked ... go inside your existing server {} block (usually in /etc/nginx/sites-available/ or /etc/nginx/conf.d/); the redirect snippets are complete server blocks of their own. The www and non-www redirects include placeholder Let's Encrypt certificate paths, because nginx won't start a listen 443 ssl block without a certificate, so check these match yours.

After editing, run sudo nginx -t to test the config and sudo systemctl reload nginx to apply it, and keep a backup of the working config first. Characters that would break the config, such as semicolons, braces and spaces, are removed from what you type. For headers such as HSTS, use the HTTP Security Headers Generator.