NGINX Configuration Generator
Generate secure, optimized, production-ready NGINX server blocks for reverse proxies, Single Page Apps, SSL/TLS, and WebSockets.
1. Select Server Architecture / Application Template
# ==========================================================================
# NGINX Configuration for: example.com
# Generated via Stilest Nginx Configuration Generator
# ==========================================================================
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
# Enforce HTTPS redirect
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com www.example.com;
# SSL / TLS Modern Security
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:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
# HSTS (Strict-Transport-Security)
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# Client max upload body size
client_max_body_size 20M;
# Enhanced 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 Referrer-Policy "strict-origin-when-cross-origin" always;
# Gzip Compression
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml font/woff2 application/font-woff image/svg+xml;
# Reverse Proxy to Node.js / Next.js
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
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;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Static Asset Caching (CSS, JS, Images, Fonts)
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|webp|avif)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable";
access_log off;
}
# Deny access to hidden files (.git, .env, etc.)
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}sudo nano /etc/nginx/sites-available/example.com && sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ && sudo nginx -t && sudo systemctl reload nginx
Architecting High-Performance NGINX Configurations
NGINX powers over 30% of the world's highest traffic web applications because of its asynchronous, event-driven worker model. A well-configured Nginx instance serves static assets near wire-speed while offloading SSL termination and request buffering from Node.js, Python, or Go microservices.
Common Deployments
- ✓Node.js, Next.js & Bun Reverse Proxy
Effortlessly forward port 80/443 traffic to your local Node or Bun process at 127.0.0.1:3000 with essential proxy headers and full WebSocket handshake support.
- ✓React, Vue & Vite SPA Deployment
Generate bulletproof HTML5 history API routing (`try_files $uri $uri/ /index.html;`) so deep links and client-side page refreshes never yield 404 errors.
- ✓Let's Encrypt SSL & TLS Hardening
Enforce HTTPS redirects, modern cipher suites (TLSv1.2 & TLSv1.3), SSL session caching, and HSTS headers to achieve an A+ on Qualys SSL Labs.
- ✓Static Asset Performance & Caching
Configure 30-day immutable browser caching for WebP, CSS, JavaScript, and font files alongside Gzip compression to minimize TTFB and bandwidth costs.
Production Features
One-Click Architecture Presets
Instant configurations for Node.js/Next.js reverse proxy, React/Vue SPAs, Python FastAPI/Django, and PHP-FPM WordPress setups.
Hardened Security Headers
Includes pre-configured X-Frame-Options, X-Content-Type-Options nosniff, Referrer-Policy, and HSTS preload flags to defend against clickjacking and MIME attacks.
WebSockets & HTTP/2 Ready
Seamlessly proxies bidirectional WebSocket upgrades for Socket.io, GraphQL subscriptions, and real-time feeds while enabling HTTP/2 binary framing.
Rate Limiting Snippets
Optionally injects memory-backed request throttling (`limit_req_zone`) to protect against scraping, brute-force bots, and DDoS amplification.
Frequently Asked Questions
Where do I save this NGINX configuration file on Ubuntu/Debian?
Save the generated file to `/etc/nginx/sites-available/yourdomain.com.conf`. Then activate it by creating a symbolic link into `/etc/nginx/sites-enabled/`: `sudo ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/` and reload Nginx via `sudo nginx -t && sudo systemctl reload nginx`.
How do I test my NGINX configuration for syntax errors before reloading?
Always execute `sudo nginx -t` in your terminal. If the syntax is valid, you will see `syntax is ok` and `test is successful`. If there are missing semicolons or path errors, it will print the exact line number.
Why do my React/Vue client routes return 404 on NGINX?
In Single Page Applications (SPAs), routes like `/dashboard` exist purely in client-side JavaScript. Without the directive `try_files $uri $uri/ /index.html;`, Nginx looks for a physical file at `/dashboard` on disk and returns a 404 Not Found error.
How does WebSocket proxying work in NGINX?
WebSockets initiate an HTTP request that upgrades the connection protocol. NGINX requires two specific headers: `proxy_set_header Upgrade $http_upgrade;` and `proxy_set_header Connection "upgrade";` alongside `proxy_http_version 1.1;` to avoid prematurely closing the socket.
More Developer Tools
Need a Brain Break? ☕
Done working on your task? Take a quick 60-second break, test your reflexes, and flap through infinite pixel obstacles in Sky Flap!