# ============================================================================== # Nginx Configuration for HuggingFace Spaces # Reverse proxy on port 7860 (HF mandatory port) routing to internal services # ============================================================================== # Run as non-root (UID 1000 on HF Spaces) # pid directive moved here since we can't write to /run/nginx.pid as non-root pid /tmp/nginx.pid; # Worker configuration worker_processes auto; error_log /dev/stderr warn; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # Temp paths writable by UID 1000 client_body_temp_path /tmp/nginx/client_body; proxy_temp_path /tmp/nginx/proxy; fastcgi_temp_path /tmp/nginx/fastcgi; uwsgi_temp_path /tmp/nginx/uwsgi; scgi_temp_path /tmp/nginx/scgi; # Logging to stdout/stderr for HF Logs tab visibility access_log /dev/stdout; # Performance sendfile on; keepalive_timeout 65; gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript; # Allow large file uploads (PDFs, media files) client_max_body_size 500M; # Upstream definitions upstream frontend { server 127.0.0.1:8502; } upstream api { server 127.0.0.1:5055; } server { # HuggingFace Spaces REQUIRES port 7860 listen 7860; server_name _; # ===================================================================== # FastAPI Swagger/OpenAPI docs - direct access to API server # These need to go directly to FastAPI, not through Next.js proxy # ===================================================================== location /docs { proxy_pass http://api/docs; 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; } location /openapi.json { proxy_pass http://api/openapi.json; 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; } location /redoc { proxy_pass http://api/redoc; 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; } # ===================================================================== # Health check endpoint (direct to API) # ===================================================================== location /health { proxy_pass http://api/health; proxy_set_header Host $host; } # ===================================================================== # All other requests go to Next.js frontend # Next.js internally proxies /api/* to FastAPI via rewrites # ===================================================================== location / { proxy_pass http://frontend; 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_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; # Long timeouts for AI operations (podcast generation, etc.) proxy_read_timeout 300s; proxy_send_timeout 300s; proxy_connect_timeout 60s; } } }