Advertisement

Nginx Config Generator

Generate Nginx server configuration blocks for reverse proxy, SSL, caching, and redirects.

Basic Settings

Features

Redirect Rules

No redirect rules added.

Generated Nginx Configuration

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name www.example.com;

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

    return 301 https://example.com$request_uri;
}

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

    # SSL Configuration
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    # Security Headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    # Gzip Compression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;

    location / {
        try_files $uri $uri/ /index.html;
    }

    # Static Asset Caching
    location ~* \.(jpg|jpeg|png|gif|ico|svg|webp|avif)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
    }

    location ~* \.(css|js|woff|woff2|ttf|eot)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Error pages
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
}
Advertisement

Related Tools

Advertisement

Frequently Asked Questions

What is an nginx server block?
An nginx server block (also called a virtual host) is a configuration section that defines how nginx handles requests for a specific domain or IP address. Each server block can have its own document root, SSL certificates, proxy settings, and location directives. Server blocks allow you to host multiple websites on a single nginx instance.
How do I enable SSL/HTTPS in nginx?
To enable SSL in nginx, you need an SSL certificate and private key. Add listen 443 ssl, ssl_certificate, and ssl_certificate_key directives to your server block. You should also add a separate server block on port 80 that redirects HTTP traffic to HTTPS. Modern best practices include enabling HTTP/2 and configuring TLS 1.2+ with strong cipher suites.
What is proxy_pass in nginx?
The proxy_pass directive tells nginx to forward incoming requests to another server, typically an application server running on a different port. This is the foundation of using nginx as a reverse proxy. For example, proxy_pass http://localhost:3000 forwards requests to a Node.js application running on port 3000. You should also set proxy headers like X-Real-IP and X-Forwarded-For.
How does gzip compression work in nginx?
Gzip compression in nginx reduces the size of responses before sending them to clients. Enable it with the gzip directive and configure which content types to compress using gzip_types. Typically, text-based formats like HTML, CSS, JavaScript, JSON, and XML benefit most from compression. Gzip can reduce file sizes by 60-80%, significantly improving page load times.
What caching headers should I set in nginx?
Common caching headers include Cache-Control, Expires, and ETag. For static assets like images, CSS, and JavaScript, set long cache durations (e.g., Cache-Control: max-age=31536000). For dynamic content, use shorter durations or no-cache directives. The expires directive in nginx is a shorthand for setting both Cache-Control and Expires headers simultaneously.
How do I set up redirects in nginx?
Nginx supports redirects using the return and rewrite directives. Use return 301 for permanent redirects and return 302 for temporary ones. The return directive is faster and preferred for simple redirects, while rewrite allows regex-based URL transformations. Always use 301 redirects for permanent URL changes to preserve SEO value.
Where do I save the nginx configuration file?
Nginx configuration files are typically stored in /etc/nginx/. The main config is /etc/nginx/nginx.conf. Site-specific server blocks go in /etc/nginx/sites-available/ with symlinks in /etc/nginx/sites-enabled/. After saving your config, test it with nginx -t and reload with sudo nginx -s reload or sudo systemctl reload nginx.

How to Use the Nginx Config Generator

Configuring nginx correctly requires understanding numerous directives and their interactions. Our visual nginx configuration generator eliminates syntax errors and helps you build production-ready server blocks in seconds. Whether you need a simple static file server or a complex reverse proxy setup, this tool generates clean, well-commented nginx configurations.

Step 1: Set your domain and basics. Enter your domain name and choose the document root directory for your website files. The generator supports both standard HTTP and HTTPS configurations with automatic SSL certificate path generation for Let's Encrypt certificates.

Step 2: Configure SSL and proxy settings. Enable SSL to generate a secure HTTPS configuration with modern TLS settings. If you are running an application server, enable reverse proxy mode and set the upstream server address. The generator includes proper proxy headers for X-Real-IP and X-Forwarded-For.

Step 3: Add performance optimizations. Enable gzip compression to reduce bandwidth usage and improve load times. Configure static asset caching with appropriate expiry headers. These optimizations can significantly improve your website performance and Core Web Vitals scores.

Step 4: Add redirect rules. Set up URL redirects for domain migration, URL restructuring, or enforcing trailing slashes. The generator supports both permanent (301) and temporary (302) redirects with clean nginx syntax.

Nginx Configuration Best Practices

A well-configured nginx server is the foundation of a performant web application. Nginx serves as a reverse proxy, load balancer, and static file server for millions of websites worldwide. It is known for its high performance, stability, and low resource consumption, making it the most popular web server for high-traffic websites.

Security should be a primary concern when configuring nginx. Always redirect HTTP to HTTPS, use TLS 1.2 or higher, configure strong cipher suites, and add security headers like X-Frame-Options, X-Content-Type-Options, and Content-Security-Policy. The generated configuration includes these security best practices by default when SSL is enabled.

Performance optimization in nginx involves several layers. Gzip compression reduces the size of text-based responses by 60-80%. Static asset caching with appropriate Cache-Control headers eliminates unnecessary re-downloads. Connection keep-alive reduces TCP handshake overhead. Worker processes and connections should be tuned based on your server hardware.

Common Nginx Configuration Patterns

Static website hosting. The simplest nginx configuration serves static files from a directory. Set the root directive to your website directory and configure index files. Add try_files to handle client-side routing for single-page applications by falling back to index.html for any path that does not match an actual file.

Reverse proxy for Node.js/Python. When running application servers like Express, Django, or Flask, nginx acts as a reverse proxy that handles SSL termination, static file serving, and request buffering. The proxy_pass directive forwards requests to your application server while nginx handles the heavy lifting of HTTP processing.

Load balancing. Nginx can distribute traffic across multiple backend servers using the upstream directive. It supports round-robin, least connections, and IP hash load balancing methods. Health checks ensure traffic is only sent to healthy backends.

Why Use Our Nginx Config Generator?

Syntax-error-free output. Manual nginx configuration is error-prone. A missing semicolon, misplaced brace, or incorrect directive can cause nginx to fail to start. Our generator produces syntactically correct configurations every time, saving you from debugging configuration errors.

Security best practices built in. The generated configurations include modern SSL settings, security headers, and proper file permission controls. You get production-ready security without needing to research and implement each security measure individually.

Completely private. Your server configuration details never leave your browser. The generator runs entirely client-side, so your domain names, internal paths, and server architecture remain confidential.

Advertisement