Nginx Production Recipes & Configuration Directory
Copy-pasteable, hardened Nginx server blocks and reverse proxy configurations. Optimized for high throughput, sub-millisecond SSL handshakes, Single-Page Applications, WebSockets, and API rate limiting.
How to Configure Nginx Reverse Proxy for Node.js, FastAPI & Go
Forward incoming public HTTP requests to internal application servers (Node.js, Express, Python FastAPI, Go, Docker) with real client IP headers.
How to Redirect HTTP to HTTPS & Configure SSL/TLS in Nginx
Force secure HTTPS connections, redirect port 80 traffic with 301 Moved Permanently, and configure Let's Encrypt / modern TLS 1.2 & 1.3 ciphers.
How to Fix React Router, Vue & SPA 404 on Reload with Nginx try_files
Solve the notorious single-page application (SPA) 404 error when refreshing client-side routes like /dashboard or /profile using Nginx try_files.
How to Configure Rate Limiting in Nginx to Prevent API Abuse & DDoS
Protect login endpoints, public REST APIs, and sensitive routes from brute-force attacks and volumetric spam using Nginx limit_req zones.
How to Configure CORS Headers & Handle OPTIONS Preflight in Nginx
Allow Cross-Origin Resource Sharing (CORS) across single-page apps, mobile apps, and microservices with automated HTTP 204 No Content preflight handling.
How to Proxy WebSockets in Nginx (Socket.io, WS, WSS)
Enable persistent real-time bidirectional communication for Socket.io, Chat engines, GraphQL subscriptions, and WebSockets over Nginx.
How to Enable Gzip & Brotli Compression in Nginx for High PageSpeed
Compress HTML, CSS, JavaScript, JSON, and SVG files dynamically on the fly to reduce network payload size by up to 75% and boost Google Lighthouse scores.
How to Set Cache-Control & Long-Lived Expires for Static Assets in Nginx
Instruct browsers and CDNs to cache hashed CSS, JS, images, and fonts with immutable 1-year lifetimes to eliminate duplicate requests.
How to Fix 413 Request Entity Too Large in Nginx (client_max_body_size)
Increase the default 1MB file upload limit in Nginx to allow large uploads (images, videos, PDF documents) without 413 errors.
How to Password-Protect Admin & Staging Sites with HTTP Basic Auth in Nginx
Restrict access to staging environments, internal docs, or admin tools with prompt-based HTTP authentication using htpasswd credentials.
Nginx Architecture & High-Performance Best Practices
Unlike thread-per-connection servers like Apache, Nginx relies on an asynchronous, non-blocking event loop using Linux epoll. A single worker process can handle over 10,000 concurrent keep-alive client connections with negligible RAM overhead.
Placing Nginx in front of internal Node.js or Python processes isolates your application from slow-loris attacks, malformed request bodies, and SSL vulnerabilities. Enforce modern TLS 1.3 ciphers, HSTS headers, and strict rate limits at the edge.
Never restart Nginx in production with systemctl restart. Always test configuration validity with sudo nginx -t and apply updates with sudo systemctl reload nginx to keep live connections uninterrupted.
Essential Nginx CLI Operations
sudo nginx -tChecks syntax without reloading
sudo systemctl reload nginxApplies changes with zero downtime
sudo tail -f /var/log/nginx/error.logStreams connection & upstream errors
sudo ln -s /etc/nginx/sites-available/site.conf /etc/nginx/sites-enabled/Symlinks config to active directory
Frequently Asked Questions About Nginx
Everything you need to know about setting up and operating Nginx in high-load production environments.
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
On Ubuntu/Debian, save server blocks in `/etc/nginx/sites-available/yourdomain.conf` and activate them by creating a symbolic link to `/etc/nginx/sites-enabled/` with `sudo ln -s /etc/nginx/sites-available/yourdomain.conf /etc/nginx/sites-enabled/`. On RHEL/CentOS, configurations typically live in `/etc/nginx/conf.d/yourdomain.conf`.