This is my nginx configuration for setup streamlit at subpath https://fullstackstation.com/streamlit-components-demo: 370
location /streamlit-components-demo {
    proxy_pass http://127.0.0.1:8501/;
}
location ^~ /static {
    proxy_pass http://127.0.0.1:8501/static/;
}
location ^~ /healthz {
    proxy_pass http://127.0.0.1:8501/healthz;
}
location ^~ /vendor {
    proxy_pass http://127.0.0.1:8501/vendor;
}
location /stream { # most important config
    proxy_pass http://127.0.0.1:8501/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;
}

For subdomain, just setup the /stream part is enough.
Hope this help.