Spaces:
Build error
Build error
| worker_processes auto; | |
| error_log /var/log/nginx/error.log warn; | |
| pid /var/run/nginx.pid; | |
| events { | |
| worker_connections 1024; | |
| use epoll; | |
| multi_accept on; | |
| } | |
| http { | |
| include /etc/nginx/mime.types; | |
| default_type application/octet-stream; | |
| # Logging | |
| log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
| '$status $body_bytes_sent "$http_referer" ' | |
| '"$http_user_agent" "$http_x_forwarded_for"'; | |
| access_log /var/log/nginx/access.log main; | |
| # Performance | |
| sendfile on; | |
| tcp_nopush on; | |
| tcp_nodelay on; | |
| keepalive_timeout 65; | |
| gzip on; | |
| gzip_types text/plain text/css application/json application/javascript text/xml application/xml; | |
| # Security headers | |
| add_header X-Frame-Options DENY always; | |
| add_header X-Content-Type-Options nosniff always; | |
| add_header X-XSS-Protection "1; mode=block" always; | |
| add_header Referrer-Policy strict-origin-when-cross-origin always; | |
| # Rate limiting zones | |
| limit_req_zone $binary_remote_addr zone=api:10m rate=30r/m; | |
| limit_req_zone $binary_remote_addr zone=auth:10m rate=10r/m; | |
| # Upstream servers | |
| upstream frontend { | |
| server frontend:3000; | |
| keepalive 32; | |
| } | |
| upstream backend { | |
| server backend:8000; | |
| keepalive 32; | |
| } | |
| server { | |
| listen 80; | |
| server_name _; | |
| # Frontend | |
| location / { | |
| proxy_pass http://frontend; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection 'upgrade'; | |
| 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_cache_bypass $http_upgrade; | |
| } | |
| # Backend API — rate limited | |
| location /api/ { | |
| limit_req zone=api burst=20 nodelay; | |
| proxy_pass http://backend; | |
| proxy_http_version 1.1; | |
| 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_read_timeout 120s; | |
| } | |
| # Auth endpoints — stricter rate limit | |
| location /api/auth/ { | |
| limit_req zone=auth burst=5 nodelay; | |
| proxy_pass http://backend; | |
| proxy_http_version 1.1; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| } | |
| # WebSocket — no rate limit, long timeout | |
| location /api/ai/chat/ws { | |
| proxy_pass http://backend; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "Upgrade"; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_read_timeout 3600s; | |
| proxy_send_timeout 3600s; | |
| } | |
| # Health check (no logging) | |
| location /health { | |
| proxy_pass http://backend/health; | |
| access_log off; | |
| } | |
| # API docs | |
| location /docs { | |
| proxy_pass http://backend/docs; | |
| } | |
| } | |
| } | |