Create Nginx Reverse Proxy Configuration
devops
Nginx
scaffolding
strict_senior
Generate production-ready Nginx config with SSL, load balancing, caching, and rate limiting.
By ethan_w
12/8/2025
Prompt
Create a production-ready Nginx reverse proxy configuration for [APPLICATION_NAME] with the following specifications:
Requirements
- Application name: [APPLICATION_NAME]
- Domain name: [DOMAIN_NAME]
- Backend servers: [SERVER_1:PORT], [SERVER_2:PORT], [SERVER_3:PORT]
- Load balancing algorithm: [round-robin/least_conn/ip_hash]
- SSL certificate path: [CERT_PATH]
- Static files location: [STATIC_FILES_PATH]
- API endpoints: [/api/, /graphql, /ws]
- Caching requirements: [YES/NO]
- Rate limiting: [REQUESTS_PER_SECOND] requests/second
- WebSocket support: [YES/NO]
- Max body size: [SIZE]MB
Deliverables
Generate complete Nginx configuration including:
Main server block for HTTP (port 80):
- Listen directive with server_name [DOMAIN_NAME]
- Redirect all HTTP traffic to HTTPS (301)
HTTPS server block (port 443):
- SSL/TLS configuration with HTTP/2
- SSL certificate and key paths
- Strong cipher suites (TLSv1.2, TLSv1.3)
- Security headers (HSTS, X-Frame-Options, etc.)
Upstream configuration for [BACKEND_SERVERS]:
- Upstream block named "backend"
- Load balancing with [ALGORITHM]
- Server definitions for all [BACKEND_SERVERS]
- Health check parameters
- Keepalive connections
Proxy configuration for all locations:
- Proxy headers (Host, X-Real-IP, X-Forwarded-For, X-Forwarded-Proto)
- WebSocket support headers if [WEBSOCKET_SUPPORT]
- Proxy timeouts and buffer settings
- Client max body size [MAX_BODY_SIZE]
API routing for [API_ENDPOINTS]:
- Location blocks for each API path
- proxy_pass to backend upstream
- Rate limiting zone configuration
- CORS headers if needed
Static file serving if [STATIC_FILES_PATH]:
- Root directive pointing to [STATIC_FILES_PATH]
- try_files for SPA routing
- Long-term caching for assets (images, fonts, CSS, JS)
- Gzip compression configuration
Caching configuration if needed:
- proxy_cache_path definition
- Cache zone configuration
- Cache validity rules
- Cache control headers
- Stale cache serving on errors
Rate limiting:
- limit_req_zone definition
- Apply [REQUESTS_PER_SECOND] limit to API routes
- Burst configuration
- Rate limit error handling
Security and performance:
- Gzip compression for text content
- Client body buffer size optimization
- Connection timeouts
- Log format and access logs
Output complete nginx.conf ready for production deployment.
Tags
nginx
reverse-proxy
load-balancing
devops
Tested Models
gpt-4
claude-3-opus