CausalBox / nginx.conf
Arya Patil
Initial deployment of CausalBox app
85fd14e
raw
history blame
2.48 kB
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# Gzip settings (optional, but good for performance)
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
server {
listen 7860; # Hugging Face Spaces default port for Docker SDK
server_name localhost;
# Serve Streamlit app at the root (/)
location / {
proxy_pass http://localhost:8501; # Streamlit's default port
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300s; # Increase if Streamlit app takes long to load/respond
proxy_send_timeout 300s;
}
# Serve Flask API at /api/ (or adjust as per your Flask app's routing)
# Note: Your Streamlit app should call http://localhost:5000/preprocess/upload etc. internally.
# This Nginx block is for if you wanted to expose Flask directly under /api/,
# but for internal communication, Streamlit calls Flask's internal port directly.
# However, for the Streamlit app to communicate with Flask, it *must* use `http://localhost:5000`.
# The Nginx here is primarily for serving the Streamlit app to the public.
# If your Streamlit app's FLASK_API_URL is "http://localhost:5000", Nginx doesn't mediate these internal calls.
# The Nginx config below is for direct external access to Flask, which is usually not needed when Streamlit is the frontend.
# I'll keep it simple for now, focusing on Streamlit at root.
# If you wanted to expose Flask on a subpath of the Space URL (e.g., yourspace.hf.space/flask_api)
# you would add a location block like this, but your Streamlit app would still call localhost:5000 internally.
# location /flask_api/ {
# proxy_pass http://localhost:5000/;
# 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;
# }
}
}