events { worker_connections 1024; } http { upstream api { server api:8000; } # Rate limiting limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; limit_req_zone $binary_remote_addr zone=auth:10m rate=5r/s; # Logging log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' 'rt=$request_time uct="$upstream_connect_time" ' 'uht="$upstream_header_time" urt="$upstream_response_time"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log warn; # Gzip compression gzip on; gzip_types application/json text/css application/javascript; server { listen 80; server_name localhost; # Health check location /health { proxy_pass http://api/health; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; access_log off; } # API endpoints with rate limiting location /api/ { limit_req zone=api burst=20 nodelay; proxy_pass http://api/; 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_connect_timeout 5s; proxy_send_timeout 10s; proxy_read_timeout 10s; } # Auth endpoints with stricter rate limiting location /api/auth/ { limit_req zone=auth burst=10 nodelay; proxy_pass http://api/auth/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } # Static files location /static/ { alias /app/static/; expires 1d; add_header Cache-Control "public, immutable"; } # Default location location / { proxy_pass http://api/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } }