Overview
Produces hardened, production-ready Nginx server blocks for common use cases: reverse proxy to backend apps, load balancing across multiple upstreams, SSL termination with Let's Encrypt, static file serving with caching, gzip, rate limiting, and a full set of security headers (HSTS, CSP, X-Frame-Options, etc.).
When to Use This Skill
- Setting up or replacing a reverse proxy / load balancer.
- Configuring Nginx in front of Node.js, Python, Go, or other app servers.
- Adding HTTPS or improving security headers.
Prerequisites
- Nginx installed (or in Docker).
- Domain name and ability to point DNS.
- For Let's Encrypt: certbot or cert-manager.
Steps
Basic server block structure:
listen 80 + redirect to HTTPS.
listen 443 ssl http2.
server_name.
- Root or proxy_pass.
Upstream definition for load balancing or multiple backends.
SSL/TLS:
- Modern cipher suite.
- OCSP stapling.
- Let's Encrypt paths (
/etc/letsencrypt).
Proxy settings:
proxy_pass http://backend;
proxy_set_header for X-Forwarded-*, Host, etc.
- Timeouts and buffering.
Performance:
- gzip on.
- Static file caching headers (immutable for hashed assets).
sendfile, tcp_nopush.
Security headers (include a reusable snippet):
- Strict-Transport-Security.
- Content-Security-Policy (start restrictive).
- X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy.
Rate limiting:
limit_req_zone.
- Different zones for login vs general.
Output:
- Complete
/etc/nginx/sites-available/example.com.conf.
- Symlink instructions.
nginx -t and reload commands.
- certbot command for SSL.
- Testing with
curl -I.
Examples
A full reverse proxy config for a Next.js app on port 3000 with SSL, security headers, gzip, rate limiting, and static asset caching is included, plus a load-balanced upstream example.
Edge Cases & Error Handling
- Websockets: Add
proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; etc.
- Large uploads: Increase
client_max_body_size.
- Maintenance mode: Provide a config snippet that returns 503 with a nice page.
Verification
nginx -t — config is valid.
curl -I https://example.com — correct headers, 200 or 301.
curl -I https://example.com/_next/static/... — long cache headers.
- Test rate limiting by sending many requests.
- SSL Labs test (A+ rating target).
- Success: Traffic is proxied correctly, HTTPS works, headers are secure, performance features are active.
References
1---2name: nginx-config-generator3description: Generates Nginx configurations for reverse proxying, load balancing, SSL termination, and static file serving. Use when configuring Nginx for a web server or API gateway.4license: Apache-2.05---67## Overview89Produces hardened, production-ready Nginx server blocks for common use cases: reverse proxy to backend apps, load balancing across multiple upstreams, SSL termination with Let's Encrypt, static file serving with caching, gzip, rate limiting, and a full set of security headers (HSTS, CSP, X-Frame-Options, etc.).1011## When to Use This Skill1213- Setting up or replacing a reverse proxy / load balancer.14- Configuring Nginx in front of Node.js, Python, Go, or other app servers.15- Adding HTTPS or improving security headers.1617## Prerequisites1819- Nginx installed (or in Docker).20- Domain name and ability to point DNS.21- For Let's Encrypt: certbot or cert-manager.2223## Steps24251. **Basic server block structure**:26 - `listen 80` + redirect to HTTPS.27 - `listen 443 ssl http2`.28 - `server_name`.29 - Root or proxy_pass.30312. **Upstream definition** for load balancing or multiple backends.32333. **SSL/TLS**:34 - Modern cipher suite.35 - OCSP stapling.36 - Let's Encrypt paths (`/etc/letsencrypt`).37384. **Proxy settings**:39 - `proxy_pass http://backend;`40 - `proxy_set_header` for X-Forwarded-*, Host, etc.41 - Timeouts and buffering.42435. **Performance**:44 - gzip on.45 - Static file caching headers (immutable for hashed assets).46 - `sendfile`, `tcp_nopush`.47486. **Security headers** (include a reusable snippet):49 - Strict-Transport-Security.50 - Content-Security-Policy (start restrictive).51 - X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy.52537. **Rate limiting**:54 - `limit_req_zone`.55 - Different zones for login vs general.56578. **Output**:58 - Complete `/etc/nginx/sites-available/example.com.conf`.59 - Symlink instructions.60 - `nginx -t` and reload commands.61 - certbot command for SSL.62 - Testing with `curl -I`.6364## Examples6566A full reverse proxy config for a Next.js app on port 3000 with SSL, security headers, gzip, rate limiting, and static asset caching is included, plus a load-balanced upstream example.6768## Edge Cases & Error Handling6970- **Websockets**: Add `proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade;` etc.71- **Large uploads**: Increase `client_max_body_size`.72- **Maintenance mode**: Provide a config snippet that returns 503 with a nice page.7374## Verification75761. `nginx -t` — config is valid.772. `curl -I https://example.com` — correct headers, 200 or 301.783. `curl -I https://example.com/_next/static/...` — long cache headers.794. Test rate limiting by sending many requests.805. SSL Labs test (A+ rating target).816. Success: Traffic is proxied correctly, HTTPS works, headers are secure, performance features are active.8283## References8485- [Nginx Docs](https://nginx.org/en/docs/)86- [Mozilla SSL Configuration Generator](https://ssl-config.mozilla.org/)87- [Nginx Security Headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers)88- [certbot](https://certbot.eff.org/)