Nginx Config Builder

Generate production-ready Nginx reverse proxy server blocks with SSL/TLS, HTTP/2, WebSocket support, and OWASP headers.

4.9 / 5· 148 verified ratings
•
100% Client-Side Privacy
•
Verified 2026 Engine
Loading tool engine...
Frequently Used With:UUID / GUID Generator (v4 & v1) →Cron Expression Generator & Schedule Builder →Lorem Ipsum Placeholder Text Generator →HTML Entity Encoder & Decoder →
Institutional-Grade Accuracy & Client-Side Privacy Guarantee

Unlike conventional calculator sites that send your financial numbers, payload data, or code snippets across remote web servers, Affi-Chain processes all mathematical derivations, algorithms, and data parsing 100% locally within your browser sandbox. No tracking cookies, no server-side retention, and zero transmission lag.

What is an Nginx Configuration Builder?

The Nginx Configuration Builder is an infrastructure-as-code and web server configuration tool that synthesizes hardened, production-ready nginx.conf server blocks. Created by Igor Sysoev in 2004, Nginx is the world's most widely deployed high-performance web server, reverse proxy, and Layer 7 load balancer. Designed on an asynchronous, event-driven, non-blocking architecture, Nginx handles tens of thousands of concurrent client connections with minimal memory overhead, powering modern microservices, single-page application (SPA) frontends, and API gateways.

However, authoring Nginx configuration files by hand is notoriously prone to syntax bugs and security misconfigurations. A single missing trailing slash on a proxy_pass directive, an unquoted variable, or an improper SSL cipher suite can:

  • Inadvertently strip URL path prefixes during reverse proxying.
  • Trigger infinite HTTP-to-HTTPS redirect loops behind Cloudflare or AWS Application Load Balancers.
  • Leave web applications vulnerable to Clickjacking, MIME-sniffing, and Cross-Site Scripting (XSS) attacks due to missing HTTP response headers.
  • Abort large file uploads with ambiguous 413 Request Entity Too Large errors.

The Affi-Chain Nginx Configuration Builder generates battle-tested, modular server configurations tailored for Next.js, Node.js, Python FastAPI/Django, Go, and static React SPAs. It incorporates modern SSL/TLS hardening, HTTP/2 multiplexing, WebSocket connection upgrades, and OWASP-recommended security headers directly inside your browser with zero latency.


Core Nginx Directives & Contextual Architecture Matrix

Nginx organizes directives into a strict hierarchical context tree: main → http → server → location:

Directive / BlockContextArchitectural PurposeRecommended Production Setting
server_nameserverMatches incoming HTTP Host header to the correct virtual hostserver_name affichain.com www.affichain.com;
listenserverBinds IP address, TCP port, and protocol flagslisten 443 ssl http2;
proxy_passlocationForwards traffic to an upstream application backendproxy_pass http://127.0.0.1:3000;
proxy_set_headerlocationPreserves client network identity across reverse proxy boundariesPasses Host, X-Real-IP, and X-Forwarded-Proto
try_fileslocationFallback routing mechanism for Single Page Applications (SPAs)try_files $uri $uri/ /index.html;
client_max_body_sizehttp/serverRestricts maximum allowable HTTP request body size (file uploads)client_max_body_size 25M; (Default 1M causes 413 errors)
limit_req_zonehttpDefines in-memory rate limiting state bucketlimit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;

Step-by-Step Practical Transformation Example

Below is a complete, production-grade Nginx configuration designed for a modern web application featuring an SSL/TLS terminating reverse proxy, WebSocket support, and static asset caching:

# Upstream application cluster (Next.js / Node.js)
upstream nodejs_backend {
    server 127.0.0.1:3000;
    keepalive 32; # Reuses persistent TCP connections
}

# 1. HTTP to HTTPS Canonical Redirection Server Block
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    # Let's Encrypt ACME challenge path
    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    # Redirect all plain HTTP traffic to secure HTTPS
    location / {
        return 301 https://$host$request_uri;
    }
}

# 2. Hardened Production HTTPS Server Block
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com www.example.com;

    # Modern TLS Certificates and Cipher Suites (Mozilla Modern standard)
    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 ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers off;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;

    # Defense-in-Depth OWASP Security Headers
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
    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;
    add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';" always;

    # File Upload Limits & Buffer Sizes
    client_max_body_size 20M;

    # Gzip Compression Directives
    gzip on;
    gzip_comp_level 5;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_types application/javascript application/json text/css text/plain text/xml application/xml;

    # Primary Reverse Proxy Location
    location / {
        proxy_pass http://nodejs_backend;
        proxy_http_version 1.1;

        # WebSocket Upgrade Headers
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Client Identity Preservation Headers
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Connection Timeouts
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }

    # Static Assets Long-Term Browser Caching
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2|webp)$ {
        expires 30d;
        add_header Cache-Control "public, no-transform";
        access_log off;
    }
}

Comparison Matrix: Production Reverse Proxies

Feature / MetricNginxCaddy 2TraefikApache HTTP Server
ArchitectureAsynchronous Event-DrivenGo GoroutinesGo GoroutinesProcess / Thread Pool
Memory FootprintMinimal (~10 MB per worker)Moderate (~50 MB)Moderate (~80 MB)High (~150+ MB)
Automated SSL/TLSRequires Certbot / CronNative Automatic HTTPSNative Automatic HTTPSRequires Certbot
Kubernetes IngressIndustry Standard (Ingress-Nginx)LimitedNative ProviderLimited
Configuration ModelStatic text reload (nginx -s reload)Dynamic JSON / CaddyfileDynamic labels / CRDs.htaccess / httpd.conf

Critical Edge Cases & Common Nginx Pitfalls

1. The Trailing Slash proxy_pass Disaster

The presence or absence of a trailing slash in proxy_pass fundamentally alters URI rewriting behavior:

  • Without Trailing Slash:
    location /api/ {
        proxy_pass http://127.0.0.1:8080;
    }
    
    A request to /api/users is forwarded verbatim as /api/users to the backend.
  • With Trailing Slash:
    location /api/ {
        proxy_pass http://127.0.0.1:8080/;
    }
    
    Nginx strips the /api/ matching prefix and forwards the request as /users! Mistaking this distinction breaks API routing across microservices.

2. The Cloudflare Flexible SSL Redirect Loop

If your domain uses Cloudflare with SSL mode set to "Flexible", Cloudflare communicates with your origin server over plain HTTP on port 80.

  • If Nginx has an HTTP-to-HTTPS redirect rule (return 301 https://$host$request_uri;), Nginx sends a redirect to HTTPS.
  • Cloudflare receives the redirect, connects back to port 80 over HTTP, and Nginx redirects again.
  • Result: ERR_TOO_MANY_REDIRECTS infinite loop!
  • Fix: Set Cloudflare SSL to "Full" or "Full (Strict)" and terminate real certificates on Nginx.

3. The Default 1MB Upload Cap (413 Request Entity Too Large)

By default, Nginx sets client_max_body_size 1m;. When users attempt to upload images, avatars, or PDFs exceeding 1 Megabyte, Nginx rejects the request at the proxy boundary before your backend application ever sees it. Always declare client_max_body_size 25M; (or appropriate business size) in the server block.

Frequently Asked Questions

How do you configure an Nginx reverse proxy for Node.js or Python?
Use proxy_pass pointing to your internal port (e.g. proxy_pass http://127.0.0.1:3000;) along with proxy_set_header Host $host and proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for.
How do you enable WebSocket connections in Nginx?
Set proxy_http_version 1.1; and include proxy_set_header Upgrade $http_upgrade; and proxy_set_header Connection "upgrade"; in your location block.
How does Nginx redirect HTTP to HTTPS permanently?
Configure a port 80 server block with server_name yourdomain.com; and return 301 https://$host$request_uri; to ensure all unencrypted traffic upgrades to HTTPS.

Explore Related Utilities