Deploy streamlit with nginx + docker

Hi everyone!

i developed a simple multi page website using streamlit that communicates with various containerized backends, and i was trying to deploy it with nginx.

If i link the container port to localhost the website works perfectly, but if i try to depoly it the page loads it just says “please wait” and i get the error in the picture
screenshot

I’ve already read various issues on it, so i set in the .toml file of streamlit enableCORS = false and
enableXsrfProtection=false
i’ll leave you the configuratiuon file of nginx, hope someone can help me understand what i’m doing wrong, since i’m fairly new to all this

Blockquote

upstream webapp{
    server webapp:8501;
}


server {
    listen 80;

  location / {
      proxy_pass http://webapp/;

  }

  location ^~ /static {
      proxy_pass http://webapp/static;
  }

  location _stcore/health {
      proxy_pass http://webapp/healthz;
  }

  location ^~ /vendor {
      proxy_pass http://webapp/vendor;
  }

  location /_stcore/stream { 
      proxy_pass http://webapp/stream;
      proxy_http_version 1.1; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_read_timeout 86400;
}
    

}

Hey @Futon,

@bangpradyumna shared their working nginx config here:

This is the final working nginx conf for anyone who’s facing issues.

server {
    server_name website.com;

    location / {
                proxy_pass http://127.0.0.1:8501/;
                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_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
    }

        location /_stcore/stream {
                proxy_pass http://127.0.0.1:8501/_stcore/stream;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $host;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_read_timeout 86400;
        }

}

There’s also some helpful info on this issue in this thread – if you’re using an older version of Streamlit, I’d recommend upgrading to the most recent release.

5 Likes

works perfectly, thank you very much!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.