Nginx Config Builder
Generate production-ready Nginx reverse proxy server blocks with SSL/TLS, HTTP/2, WebSocket support, and OWASP headers.
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 Largeerrors.
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 / Block | Context | Architectural Purpose | Recommended Production Setting |
|---|---|---|---|
server_name | server | Matches incoming HTTP Host header to the correct virtual host | server_name affichain.com www.affichain.com; |
listen | server | Binds IP address, TCP port, and protocol flags | listen 443 ssl http2; |
proxy_pass | location | Forwards traffic to an upstream application backend | proxy_pass http://127.0.0.1:3000; |
proxy_set_header | location | Preserves client network identity across reverse proxy boundaries | Passes Host, X-Real-IP, and X-Forwarded-Proto |
try_files | location | Fallback routing mechanism for Single Page Applications (SPAs) | try_files $uri $uri/ /index.html; |
client_max_body_size | http/server | Restricts maximum allowable HTTP request body size (file uploads) | client_max_body_size 25M; (Default 1M causes 413 errors) |
limit_req_zone | http | Defines in-memory rate limiting state bucket | limit_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 / Metric | Nginx | Caddy 2 | Traefik | Apache HTTP Server |
|---|---|---|---|---|
| Architecture | Asynchronous Event-Driven | Go Goroutines | Go Goroutines | Process / Thread Pool |
| Memory Footprint | Minimal (~10 MB per worker) | Moderate (~50 MB) | Moderate (~80 MB) | High (~150+ MB) |
| Automated SSL/TLS | Requires Certbot / Cron | Native Automatic HTTPS | Native Automatic HTTPS | Requires Certbot |
| Kubernetes Ingress | Industry Standard (Ingress-Nginx) | Limited | Native Provider | Limited |
| Configuration Model | Static text reload (nginx -s reload) | Dynamic JSON / Caddyfile | Dynamic 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:
A request tolocation /api/ { proxy_pass http://127.0.0.1:8080; }/api/usersis forwarded verbatim as/api/usersto the backend. - With Trailing Slash:
Nginx strips thelocation /api/ { proxy_pass http://127.0.0.1:8080/; }/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_REDIRECTSinfinite 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.