✓ Recommended
Nginx Reverse Proxy & Configuration
Nginx configuration for reverse proxy, load balancing, SSL termination, caching, and security hardening.
CLAUDE.md
# Nginx Reverse Proxy & Configuration
You are an expert in Nginx, reverse proxy configuration, and web server optimization.
Reverse Proxy:
- Use upstream blocks for backend server pools
- Set proxy_pass with trailing slash for path stripping: location /api/ { proxy_pass http://backend/; }
- Forward real client IP: proxy_set_header X-Real-IP $remote_addr
- Forward host header: proxy_set_header Host $host
- Set proxy_set_header X-Forwarded-Proto $scheme for HTTPS detection
SSL/TLS:
- Use ssl_protocols TLSv1.2 TLSv1.3 (disable TLSv1.0 and TLSv1.1)
- Use ssl_ciphers with modern cipher suites; prefer ECDHE key exchange
- Enable OCSP stapling: ssl_stapling on; ssl_stapling_verify on
- Set ssl_session_cache shared:SSL:10m for session resumption
- Use certbot/Let's Encrypt for free automated certificates
- Add Strict-Transport-Security header with max-age=31536000
Caching:
- Use proxy_cache_path to define cache zones on disk
- Set proxy_cache_valid for different status codes: 200 1h; 404 1m
- Use proxy_cache_key to control cache key composition
- Add X-Cache-Status header for debugging: add_header X-Cache-Status $upstream_cache_status
- Use proxy_cache_bypass for cache invalidation patterns
Security:
- Hide server version: server_tokens off
- Limit request body size: client_max_body_size 10m
- Rate limiting: limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s
- Use limit_req with burst and nodelay for traffic spikes
- Block common attack patterns with location blocks
- Add security headers: X-Frame-Options, X-Content-Type-Options, CSP
Performance:
- Enable gzip compression: gzip on; gzip_types text/plain application/json text/css
- Use sendfile on and tcp_nopush on for static file serving
- Set worker_processes auto (matches CPU cores)
- Use keepalive connections to upstream: keepalive 64 in upstream block
- Configure appropriate buffer sizes: proxy_buffer_size, proxy_buffers
Add to your project root CLAUDE.md file, or append to an existing one.