Main.ca9076db.js:2 WebSocket connection to 'wss://xx.com:19203/_stcore/stream' failed:

Dear all,

I’m having troubles deploying a streamlit application. I’m getting an error to connect to WS or WSS. I have referred to the suggestions below, but none of them have been effective.

WebsocketConnection WebSocket onerror
WebSocket connection to 'ws://testm.10jqka.com.cn/domain_test/_stcore/stream' failed:
Accessing Streamlit through reverse proxy results in "Please wait..." [SOLVED]
Streamlit, docker, Nginx, ssl/https

docker container: ubuntu20.04
anaconda virtual environment
nginx: nginx version: nginx/1.18.0 (Ubuntu)
streamlit: 1.29.0
streamlit-webrtc: 0.47.1

The reverse proxy is implemented through nginx with the following simple configuration as suggested in other posts:

map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }


#HTTP server 

server {
        listen 80;
        server_name xxx.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 ^~/static {
            proxy_pass http://127.0.0.1:8501/static/;

	}

        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;
        }

    }

# HTTPS server

server {

        listen 443 ssl;
        server_name xxx.com;
        ssl_certificate xxx.crt;
        ssl_certificate_key xxx.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 5m;
        ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers on;
	ssl_verify_client off;
	add_header Access-Control-Allow-Origin *;
	proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_read_timeout 86400;

        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_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_http_version 1.1;
        }

        location ^~/static {
            proxy_pass http://127.0.0.1:8501/static/;

	}

        location /_stcore/stream {
            proxy_pass http://127.0.0.1:8501/_stcore/stream;
            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";
            proxy_http_version 1.1;
            proxy_read_timeout 86400;
        }



}



I think my problem is caused by the fact that I have mapped port 443 to 19203 in the docker container, resulting in requests for resources having to be coupled with the port wss://xxx.com:19203/_stcore/stream. but I’m not sure how I should fix this.