worker_processes 1; pid /tmp/nginx.pid; error_log stderr info; # Log to stderr to see errors in HF Space Logs events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # HF Space runs as non-root, use /tmp for everything access_log /dev/stdout; client_body_temp_path /tmp/client_temp; proxy_temp_path /tmp/proxy_temp; fastcgi_temp_path /tmp/fastcgi_temp; uwsgi_temp_path /tmp/uwsgi_temp; scgi_temp_path /tmp/scgi_temp; sendfile on; keepalive_timeout 65; upstream streamlit { server 127.0.0.1:8501; } upstream fastapi { server 127.0.0.1:8000; } upstream prometheus { server 127.0.0.1:9090; } server { listen 7860; server_name localhost; # Health endpoint for HF readiness check location /health { proxy_pass http://fastapi/health; proxy_set_header Host $host; } # FastAPI Documentation location /docs { proxy_pass http://fastapi/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 /redoc { proxy_pass http://fastapi/redoc; proxy_set_header Host $host; } location /openapi.json { proxy_pass http://fastapi/openapi.json; proxy_set_header Host $host; } # FastAPI API Endpoints location /predict { proxy_pass http://fastapi/predict; proxy_set_header Host $host; } location /predictions { proxy_pass http://fastapi/predictions; proxy_set_header Host $host; } # Prometheus UI location /prometheus/ { proxy_pass http://prometheus/prometheus/; 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; } # Streamlit (Catch-all) location / { proxy_pass http://streamlit; 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 X-Forwarded-Host $host; # WebSocket support for Streamlit proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 86400; # Prevent 502 if Streamlit is slow proxy_connect_timeout 60s; proxy_send_timeout 60s; } } }