I get the following error in console: main.35aa1d35.chunk.js:1 WebSocket connection to 'ws://dashboard-aircare.mapshalli.org/stream' failed: Error during WebSocket handshake: Unexpected response code: 400
Most of the answers in this forum point to a standard stackoverflow response regarding Apache proxy configuration. I am hoping to get a concrete answer that is specific to streamlit. Thank you!
Thank you! Following the path, I found the answer. <VirtualHost *:80>
  ServerName dashboard-aircare.mapshalli.org
  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket
  RewriteRule /(.*) ws://localhost:8501/$1 [P]
  RewriteCond %{HTTP:Upgrade} !=websocket
  RewriteRule /(.*) http://localhost:8501/$1 [P]
  ProxyPassReverse / http://localhost:8501 </VirtualHost>
In your case, I believe you are viewing partial content because the websocket is not getting forwarded. streamlit is relying on websockets for transporting its data.
<VirtualHost *:80>
  RewriteEngine on
  RewriteCond %{SERVER_NAME} =dashboard-aircare.mapshalli.org
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>
<VirtualHost *:443>
  ServerName dashboard-aircare.mapshalli.org
  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket
  RewriteRule /(.*) ws://localhost:8501/$1 [P]
  RewriteCond %{HTTP:Upgrade} !=websocket
  RewriteRule /(.*) http://localhost:8501/$1 [P]
  ProxyPassReverse / http://localhost:8501
  SSLCertificateFile somepath
  SSLCertificateKeyFile someotherpath </VirtualHost>
We are permanently directing from http:80 to https:443 and then proxying https:443 to http:8501 and ws:8501
Thank you so much for your help, but I’m afraid it still isn’t working. Like I said in my post, I’m fairly noob with these subjects, so I’m afraid I’m missing something basic.
And the streamlit file is located at /var/www/example.com/html/, called streamlit_test.py, as I followed this tutorial to get me started in Apache configuration.
<VirtualHost *:80>
  ServerName streamlit.group.pt
  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket
  RewriteRule /(.*) ws://localhost:8502/$1 [P]
  RewriteCond %{HTTP:Upgrade} !=websocket
  RewriteRule /(.*) http://localhost:8502/$1 [P]
  ProxyPassReverse / http://localhost:8502 </VirtualHost>
Once this is done please post the messages that you see. If you can keep it running, I can have a look from my system.
I wish I could keep it running, but these links and servers are currently only working inside my company’s intranet, hence why I need to use a VPN. Sorry about that and once again, thanks for your time and help!
Thank you for the script and i have changed the config file. The next question is when i run the Apache webserver, what will be the address given in the browser? Sorry because iam very new to hosting apps on webserver.
I have the same problem I need to run my streamlit application on my apache2 server directly.
Today I run the streamlit command run streamlit.py, it works perfectly. Now I would like to deploy this on my apache2 server, Do you have a concise and simple tutorial to do this?
update: loaded 2 extra proxy modules in apache fixed above issue.
but drop to “please wait” for ever issue.
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so (enabled for streamlit)
LoadModule proxy_module modules/mod_proxy.so (default loaded)
LoadModule proxy_http_module modules/mod_proxy_http.so (enabled for streamlit)
8502 has below settings as instructed, but not work.
–server.enableCORS=false
–server.enableXsrfProtection=false
–server.enableWebsocketCompression=false
I have tried with this method and config file on my server which runs on ubuntu 20.04 with apche2.
it prints “please wait…” and nothing else. I literally tried every method on the internet to solve this. any help here?
how can I diagnose this?
Hi All,
Just would like to share some of my recent experience with streamlit.
I find that I could not find a way to proxy streamlit with apache2 on a VPS (ssh and Ubuntu 18).
Finally I end up using streamlit with nginx which work perfectly well now.
I struggled with this for 24h. @aymeri_baldelli 's code works like a charm. I implemented your solution but then I was still facing an issue with the WebSockets. Turned out it was a 403 error, which was itself due to CORS issues. Changing the [browser] serverAddress to my actual’s server address in the Streamlit config.toml file fixed it for me.
Hi all, i am still very confused on how to deploy streamlit apps on apache. I am also new to deployment and apache in general so maybe thats why. I added <VirtualHost :80>
ServerName MY_SERVER_NAME
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /(.) ws://localhost:8501/$1 [P]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /(.*) http://localhost:8501/$1 [P]
ProxyPassReverse / http://localhost:8501
to my httpd-vhosts and enabled the necessary modules. Now i start streamlit with streamlit run app.py --server.address localhost --server.port 8501 and restart the apache. Now external calls to MY_SERVER_NAMEshould be handled by the streamlit app right? For me its not working, i probably have a gross mistake in my code or my understanding.