Hi, I want to run streamlit inside a docker container that is hosted on an AWS EC2 instance.
The company configured the AWS instance to only be accessible from a certain IP range thus providing the URL would not help with this use case.
Locally every thing runs fine, by both using direct access using port 8501 but also by using nginx.
On AWS however it does not.
Remark: When I access the instance via ssh and configure a port forwarding, everything works as fine.
When I want to accress the website regularly by using IP:Port, I get a website that only shows the skeleton:
The health check (ip:port/_stcore/health) also returns status code 200.
I also read this URL remote-start and used “python -m streamlit run --server.address 0.0.0.0 --server.port=8501 --server.enableCORS=false --server.enableWebsocketCompression=false --server.enableXsrfProtection=false index.py”. That didn’t change anything either.
There seem to be websocket related issues:
Do you have any ideas how to solve this issue?
I really hope the streamlit team will do more testing with nginx reverse proxies and come up with a troubleshooting guide. I have the same problem, but only from browsers other than Safari for some reason. I used to have this problem on ANY browser when accessing the application from outside of the intranet where it’s deployed (and still it worked exclusively with the intranet-facing IPaddress:8501).
What I can advise is that you add this to the configuration to NginX:
location / {
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;
proxy_pass http://YOUR-APP-IP:8501/;
}
location /_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;
proxy_pass http://YOUR-APP-IP:8501/_stcore/stream/;
}
Thanks for your reply. I found this exact approach in another post but unfortunatley it did not resolve my issue. My issue is also not related to nginx as it is exactly the same whether if I try to access the app via nginx or directly via exposed port
1 Like
In this case you can try taking the trailing slash out of the location descriptor.
location /_stcore/stream { # notice no slash trailing here
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;
proxy_pass http://YOUR-APP-IP:8501/_stcore/stream; # notice no slash trailing here either
}
You may want to do this with the parent location too if it’s not root, or as an alternative, go for the descriptor as location = /_stcore/stream/
, which should work as well. Refer to this article as to the rationale for this.
Note that this took some time for me to figure out, and that it’s quite unbelievable that nobody from the dev team seems to know this. I swear to you this is 90% of the problems people are getting with streamline behind a reverse proxy, and in tens of posts on this matter I have seen nobody mentioning this.