Streamlit with Apache reverse proxy - "Please wait..."

Hi all,

Setup:

Streamlit 1.4.0 deployed as a docker container, listening on port 8051, on an ec2 instance. Apache 2.4.18, on another node, is a reverse proxy to the streamlit app. Apacheā€™s proxy, proxy_http and proxy_wstunnel modules are enabled.

Errors:

  1. ā€œPlease waitā€¦ā€ - message on the browser when the proxy URL is hit. The app loads fine when itā€™s accessed directly via http://<ec2_host_fqdn>:8051 though.

  2. Firing the proxy URL ā€˜https://streamlit-weekly.proxy.app.infoā€™ (internal domain), on chromeā€™s debug console:

    WebSocket connection to 'wss://streamlit-weekly.proxy.app.info/stream' failed: WebSocket is closed before the connection is established.

    Uncaught Error: Unsupported state transition.
    State: PINGING_SERVER
    Event: CONNECTION_TIMED_OUT
     at Po.stepFsm (main.cb6e038a.chunk.js:2:491430)
     at main.cb6e038a.chunk.js:2:494477
    

Apache vhost:

<VirtualHost *:443>
    ServerName streamlit-weekly.proxy.app.info

  ## Vhost docroot
  DocumentRoot "/var/www/html"

  ## Directories, there should at least be a declaration for /var/www/html

  <Directory "/var/www/html">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Require all granted
  </Directory>

  ## Logging
  ErrorLog "/var/log/apache2/streamlit-weekly.proxy.app.info_error_ssl.log"
  ServerSignature Off
  CustomLog "/var/log/apache2/streamlit-weekly.proxy.app.info_access_ssl.log" combined 

  ## Proxy rules
  ProxyRequests Off
  ProxyPass / http://streamlit01.app.us-west-2.private:8501/
  ProxyPassReverse / http://streamlit01.app.us-west-2.private:8501/

   <Location "/stream">
      ProxyPass wss://streamlit01.app.us-west-2.private:8501/stream
      ProxyPassReverse wss://streamlit01.app.us-west-2.private:8501/stream
   </Location>

  ## SSL directives
  SSLEngine on
  SSLCertificateFile      "/etc/ssl/certs/ssl-cert-snakeoil.pem"
  SSLCertificateKeyFile   "/etc/ssl/private/ssl-cert-snakeoil.key"
  SSLCACertificatePath    "/etc/ssl/certs"
  SSLProxyEngine On
</VirtualHost>

I referred quite a number of posts but I wasnā€™t able to find anything specific to Apacheā€™s reverse proxy settings. Any help will be appreciated.

Thanks.

4 Likes

I am having a similar issue. I created a streamlit app and dockerized it. Now trying to reverse proxy my Apache server to connect to this docker container. But, the browser shows ā€œPlease Waitā€ and on inspecting the web page, the console shows the ā€œWebsocket connection failedā€.
I am not well versed in how to upgrade the connection to websockets from my Apache SSL config.
Also, I am reverse proxying the docker IP to a subfolder rather than using the ā€œ/ā€. Like HTTP://my_server_name/my_awesome_app/

If you found a solution then please share.

Also looking for a solution to this. Running a streamlit app on Ubuntu behind Apache2 with LetsEncrypt, says ā€œPlease waitā€¦ā€ forever and giving the same messages everyone shows here.

This still happens when I start the app using streamlit run app.py with the flags

--server.enableCORS=false
-- server.enableWebsocketCompression=false
--server.headless=true
--server.port=8501

My apache vhost file(/etc/apache2/sites-available/dashboard.mysite.io.conf)

<VirtualHost *:80>
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =dashboard.mysite.io
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI}     [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
   ServerName dashboard.mysite.io

   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 /etc/letsencrypt/live/dashboard.mysite.io/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/dashboard.mysite.io/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Hi. Have you solved it?

I too face the same issue even without ssl and not dockerised. I get the same error as explained. How to resolve this? Stuck with ā€œPlease waitā€¦ā€

1 Like

Hi. Have you solved it?

I am running into the same issue. So far iā€™ve tried everything that i came across

To the more savy, info from the logs might be useful. In there (/var/logs/apache2/error.log) I found repeated entries of

 [proxy_http:error] [pid 2901776:tid 140256410052160] [client XX.XX.XX.XX:XXXXX] AH01114: HTTP: failed to make connection to backend: 0.0.0.0, referer: https://my.domain.com/

Does that make sense to anyone?

Also just something I noticed: When i start the app from vscode on the remote, vscode can open the app with a forwarded port without a problem. At this point I am rather clueless but hope, that this can somehow help in finding the issue.

In my case the following lines in the apache configuration did the trick:

        SSLProxyEngine on
        RewriteEngine On
        RewriteCond %{HTTP:Connection} Upgrade [NC]
        RewriteCond %{HTTP:Upgrade} =websocket [NC]
        RewriteRule /(.*) ws://0.0.0.0:8501/$1 [P,L]
        ProxyPassReverse / http://0.0.0.0:8501/ 
        ProxyPass / http://0.0.0.0:8501/

When comparing that to the above i think that the main difference is the
RewriteCond %{HTTP:Connection} Upgrade [NC].

Hope that helps others, too!

This solution helped, but then itā€™s stripping logged-in user details from request headers. Could you please tell how to get them? I need to grant the access based on user roles.