Nginx Config Generator

Build an Nginx server block for a static site or a reverse proxy, with HTTPS, Gzip, caching and security headers. The config updates as you change the options.

Connect:

Server Configuration

One or more domains, separated by spaces

Folder that holds your site's files

Default: 80

e.g., 10M, 100M, 1G

Default: 65

Hardening hides the Nginx version, blocks hidden files like .env and .git, and adds HSTS when HTTPS is on.

💡 How to Use

1. Configure your server settings above
2. Copy or download the generated config
3. Save it as /etc/nginx/sites-available/your-site
4. Enable it: sudo ln -s /etc/nginx/sites-available/your-site /etc/nginx/sites-enabled/
5. Test and reload: sudo nginx -t && sudo systemctl reload nginx

Generated Nginx Configuration

# Nginx site config for example.com (generated at codewithmuh.com)
# Save as /etc/nginx/sites-available/example.com (or /etc/nginx/conf.d/example.com.conf)
# then run: sudo nginx -t && sudo systemctl reload nginx

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /var/www/html;
    index index.html index.htm;

    # Hardening
    server_tokens off;

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;
    # Tune a Content-Security-Policy for your site before turning it on:
    # add_header Content-Security-Policy "default-src 'self'" always;

    # Gzip compression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_comp_level 3;
    gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml;

    # Block hidden files like .env and .git (but allow .well-known)
    location ~ /\.(?!well-known) {
        deny all;
    }

    # Browser caching for static assets
    location ~* \.(?:jpg|jpeg|png|gif|webp|avif|ico|svg|css|js|woff2?)$ {
        expires 1d;
        access_log off;
        try_files $uri =404;
    }

    location / {
        try_files $uri $uri/ =404;
    }

    # Logging
    access_log /var/log/nginx/example_com.access.log;
    error_log /var/log/nginx/example_com.error.log;

    # Client settings
    client_max_body_size 10M;
    keepalive_timeout 65;
}

Copy this configuration to your Nginx sites-available directory and reload Nginx.

Configuration Summary

Server Type

Static Site (hardened)

HTTPS

Off

Compression

Medium (3)

Caching

1 day

⚡ Quick Commands

# Test configuration
nginx -t

# Reload Nginx
systemctl reload nginx

# Check Nginx status
systemctl status nginx

# View error logs
tail -f /var/log/nginx/error.log

🖥️ Production Ready

Generate optimized Nginx configurations with security headers, compression, and caching for production use.

🔒 Security Focused

Security headers, modern TLS settings, an HTTP to HTTPS redirect, optional rate limiting, and blocking of hidden files.

⚡ Performance Optimized

Configurations include gzip compression, browser caching, keepalive connections, and other performance optimizations.