Spaces:
Build error
Build error
| # Nginx config for Hugging Face Spaces single-container deployment | |
| # All traffic enters on port 7860 | |
| # /api/* and /ws/* β FastAPI (port 8000) | |
| # everything else β Next.js (port 3000) | |
| worker_processes 1; | |
| error_log /var/log/nginx/error.log warn; | |
| pid /run/nginx.pid; | |
| events { | |
| worker_connections 512; | |
| } | |
| http { | |
| include /etc/nginx/mime.types; | |
| default_type application/octet-stream; | |
| access_log /var/log/nginx/access.log; | |
| sendfile on; | |
| keepalive_timeout 65; | |
| client_max_body_size 10m; | |
| # Gzip | |
| gzip on; | |
| gzip_types text/plain text/css application/json application/javascript text/xml; | |
| server { | |
| listen 7860; | |
| server_name _; | |
| # ββ Health check (served by FastAPI) ββββββββββββββββββββββββββββββ | |
| location = /health { | |
| proxy_pass http://127.0.0.1:8000/health; | |
| proxy_set_header Host $host; | |
| access_log off; | |
| } | |
| # ββ API routes β FastAPI ββββββββββββββββββββββββββββββββββββββββββ | |
| location /api/ { | |
| proxy_pass http://127.0.0.1:8000/api/; | |
| 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_set_header X-Forwarded-Proto $scheme; | |
| proxy_read_timeout 120s; | |
| proxy_connect_timeout 10s; | |
| } | |
| # ββ WebSocket β FastAPI βββββββββββββββββββββββββββββββββββββββββββ | |
| location /api/ai/chat/ws { | |
| proxy_pass http://127.0.0.1:8000/api/ai/chat/ws; | |
| 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; | |
| } | |
| # ββ FastAPI docs ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| location /docs { | |
| proxy_pass http://127.0.0.1:8000/docs; | |
| proxy_set_header Host $host; | |
| } | |
| location /openapi.json { | |
| proxy_pass http://127.0.0.1:8000/openapi.json; | |
| proxy_set_header Host $host; | |
| } | |
| location /redoc { | |
| proxy_pass http://127.0.0.1:8000/redoc; | |
| proxy_set_header Host $host; | |
| } | |
| # ββ Next.js static assets (cached) βββββββββββββββββββββββββββββββ | |
| location /_next/static/ { | |
| proxy_pass http://127.0.0.1:3000/_next/static/; | |
| proxy_cache_valid 200 1y; | |
| add_header Cache-Control "public, max-age=31536000, immutable"; | |
| } | |
| # ββ Everything else β Next.js βββββββββββββββββββββββββββββββββββββ | |
| location / { | |
| proxy_pass http://127.0.0.1:3000; | |
| 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_set_header X-Forwarded-Proto $scheme; | |
| proxy_cache_bypass $http_upgrade; | |
| proxy_read_timeout 60s; | |
| } | |
| } | |
| } | |