Deploy Streamlit with NGINX with SSL

Hello,

I have docker container with NGINX and with that configuration

map $http_upgrade $connection_upgrade {
default upgrade;
β€˜β€™ close;
}

server {
    listen 80;
    listen 443 ssl;
    server_name server_name.com;

    ssl_certificate /etc/nginx/ssl/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/privkey.pem;

    location / {
        proxy_pass http://192.168.50.140: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://192.168.50.140:8501/_stcore/stream;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_read_timeout 86400;
    }
}

On my server I have a basic application streamlit. For testing connection I leave just that

import streamlit as st


def main():
    st.title("Basic Streamlit App")

    st.write("This is a basic Streamlit app for testing purposes.")

    # Add more Streamlit components as needed
    st.write("Feel free to modify this code and add more components.")


if __name__ == "__main__":
    main()

I set version 1.23.0 but with latest version I had the same issue.

Connection via http is working.
Connection with https is not working
I got
WebsocketConnection WebSocket onerror
main.e13854e4.js:2 WebSocket connection to β€˜wss://server_name.com/_stcore/stream’ failed:

I read guide and went through the solutions but nothing helped

also this article

I added necessary configuration based on that
https://nginx.org/en/docs/http/websocket.html

I added that one as well /_stcore/stream to my NGINX configuration.

Please help me. Maybe I missed some detailes. Thank you.