0

I have an issue when I try to deploy my streamlit app from my windows server to my corporate PC... The problem seems to be related to the WebSocket connection… On my PC browser, I see this error:

WebSocket connection to 'wss://XXXXXXXX/_stcore/stream' failed:

Here is my NGINX config file:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8501; #80
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location /stream {
            proxy_pass  http://127.0.0.1:8501/stream;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    server {

        server_name XXXXXXXXXX;#my_domain

        listen [::]:443 ssl; # managed by Certbot
        listen 443 ssl; # managed by Certbot

        ssl_certificate "C:\Users\YYYYYYYYYYY\cert.pem"; # managed by Certbot
        ssl_certificate_key "C:\Users\YYYYYYYYYYY\key.pem"; # managed by Certbot
        #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

        keepalive_timeout 10;

        location / {
            proxy_pass http://127.0.0.1:8502/;
            proxy_set_header Host $http_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_redirect off;
            proxy_http_version 1.1;

            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
        }

        location /_stcore/stream {
            proxy_pass http://127.0.0.1:8502/_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_set_header Sec-WebSocket-Extensions $http_sec_websocket_extentions;
            proxy_read_timeout 86400;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

        # location ^~ /healthz {
        #     proxy_pass http://127.0.0.1:8502/healthz;
        # }

    }

}

And my Streamlit config file

[server]
port = 8502
enableCORS = false
enableXsrfProtection = false
headless = true

I have tried many configurations but none worked... Any help would be greatly appreciated !

1
  • Have you tried accessing the app directly at port 8502 on the server, bypassing nginx, to see if the Streamlit application works correctly? Commented Dec 4, 2024 at 13:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.