Streamlit deployment with nginx

Hi everyone,

I know this topic has been discussed before but the answers didn’t solve my problem.
I am trying to deploy a simple streamlit app on a server (@ip = my-ip) and access it through another machine.
Here is my streamlit config.toml

[server]
headless = true
port = 8080

my nginx config file :

server {
    listen 8081;
    server_name my-ip;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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 /_stcore/stream {
        proxy_pass http://127.0.0.1:8080/_stcore/stream;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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_read_timeout 86400;
    }
}

When I try to access http://my-ip:8081/ I have the error " - WebSocket connection to ‘ws://my-ip:8501/_stcore/stream’ failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
"
I think I’ve tried every solution I found on the forum but none of them solved my problem.
Did anyone face the same issue ?

Thank you

The websocket connection should go to port 8081 automatically. In your case it seems to be going to 8501 (the default) instead. Do you have any config settings you pass to the streamlit server at startup? Either in config.toml or on the command line. Setting browser. serverPort could cause the issue you mentioned.