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.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: devops10 tags: nginx, reverse-proxy, ssl, load-balancing, security-headers, gzip11---1213## Overview1415Produces 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.).1617## When to Use This Skill1819- Setting up or replacing a reverse proxy / load balancer.20- Configuring Nginx in front of Node.js, Python, Go, or other app servers.21- Adding HTTPS or improving security headers.2223## Prerequisites2425- Nginx installed (or in Docker).26- Domain name and ability to point DNS.27- For Let's Encrypt: certbot or cert-manager.2829## Steps30311. **Basic server block structure**:32 - `listen 80` + redirect to HTTPS.33 - `listen 443 ssl http2`.34 - `server_name`.35 - Root or proxy_pass.36372. **Upstream definition** for load balancing or multiple backends.38393. **SSL/TLS**:40 - Modern cipher suite.41 - OCSP stapling.42 - Let's Encrypt paths (`/etc/letsencrypt`).43444. **Proxy settings**:45 - `proxy_pass http://backend;`46 - `proxy_set_header` for X-Forwarded-*, Host, etc.47 - Timeouts and buffering.48495. **Performance**:50 - gzip on.51 - Static file caching headers (immutable for hashed assets).52 - `sendfile`, `tcp_nopush`.53546. **Security headers** (include a reusable snippet):55 - Strict-Transport-Security.56 - Content-Security-Policy (start restrictive).57 - X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy.58597. **Rate limiting**:60 - `limit_req_zone`.61 - Different zones for login vs general.62638. **Output**:64 - Complete `/etc/nginx/sites-available/example.com.conf`.65 - Symlink instructions.66 - `nginx -t` and reload commands.67 - certbot command for SSL.68 - Testing with `curl -I`.6970## Examples7172A 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.7374## Edge Cases & Error Handling7576- **Websockets**: Add `proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade;` etc.77- **Large uploads**: Increase `client_max_body_size`.78- **Maintenance mode**: Provide a config snippet that returns 503 with a nice page.7980## Verification81821. `nginx -t` — config is valid.832. `curl -I https://example.com` — correct headers, 200 or 301.843. `curl -I https://example.com/_next/static/...` — long cache headers.854. Test rate limiting by sending many requests.865. SSL Labs test (A+ rating target).876. Success: Traffic is proxied correctly, HTTPS works, headers are secure, performance features are active.8889## References9091- [Nginx Docs](https://nginx.org/en/docs/)92- [Mozilla SSL Configuration Generator](https://ssl-config.mozilla.org/)93- [Nginx Security Headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers)94- [certbot](https://certbot.eff.org/)