nginx Config Generator

Build an nginx server block: HTTPS redirect, www handling, redirects, gzip, caching, security headers, hidden file blocking and single-page app routing.

Processed on your device. Files are not uploaded

How to make an nginx config

  1. Describe the server

    Enter your domain.

  2. Pick the rules

    Redirect HTTP to HTTPS, handle www, add redirects, compress text, cache static files, or support single-page apps.

  3. Add protection

    Send security headers and block hidden files.

  4. Save it

    Copy the server block into your nginx configuration.

    Run nginx -t to check it before you reload.

Worked example

This is what nginx Config Generator gives for its own sample values. Open the tool above and change anything to try your own.

Domain
example.com
Redirect HTTP to HTTPS
Yes
www handling
Leave as it is
Compress text files
Yes
Cache images, CSS and JavaScript
Yes
Add security headers
Yes

nginx server block

# Generated by Sarva Tools
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com www.example.com;
    root /var/www/example.com/public;
    index index.html index.htm;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
...

About nginx Config Generator

Build an nginx server block for a site: redirect HTTP to HTTPS, handle www, add redirects, compress text, cache static files, send security headers, block hidden files and support single-page apps.

FAQs

Do I need to change anything?

Yes. Set the root folder and the certificate paths to match your server.

How do I check it?

Run nginx -t to test the file, then reload nginx.

Does it work on Apache?

No. Use .htaccess Generator.

Related tools