[HELP NEEDED...] Streamlit Keep Connecting with Reverse Proxy Set-up (Apache2)

I have recently bought a Raspberry Pi and I am trying to launch the Streamlit app (version 0.62.0) with a reverse proxy set up on my Apache2 Server…however, the page keeps saying “Please Wait…”.

However, the app loads perfectly okay when I access it within the local network, i.e., 192.168.0.163:8501 so I believe that there might be something wrong with my .conf files…

<VirtualHost :80>
** ServerName pooh.zenfleurs.com
*
** ServerAlias pooh.zenfleurs.com**
** ProxyPreserveHost on**
** ProxyRequests Off**
** ProxyPass / http://localhost:8501/**
** ProxyPassReverse / http://localhost:8501/**

I have also tried with the below but it seems that none of them could get me throguh…

  • Creating a .toml file at ~/.streamlit/config.toml and write enableCORS=false

  • Running the command line sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8501

Appreciate if something could help me or give me a hint on what’s wrong here…

Thanks!

1 Like

Same problem. I already opened up another post, but no replies yet. Really looking forward to a solution!

@aminsadeghi

I have spent some time on the issue and eventually found a solution to the problem (inspired from the solution found here. You may try to follow the below steps and see if it helps:

(Indeed, I have my Raspberry Pi reinstalled earlier today due to some other technical issues and hence I am sure that the below steps work well in a newly installed Debian 10 OS that is hosted with an Apache2 server :smiley:)

  1. Create a config.toml under ~/. streamlit folder:

    cd ~/. streamlit
    sudo nano config.toml

  2. Type the below in the config.toml and save it:

    [server]
    port = 8501
    enableCORS = false

  3. Ensure that the below a2enmods are enabled:

    sudo a2enmod rewrite
    sudo a2enmod proxy
    sudo a2enmod proxy_http
    sudo a2enmod proxy_wstunnel

  4. Navigate/ Create an Apache .conf file and type the below:
    (Replace the text with your domain in the <Your Domain/ Sub-domain> below)

    <VirtualHost :80>
    ServerName <Your Domain/ Sub-domain>
    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>

  5. sudo a2ensite the config file created in the last step and then sudo service apache2 restart should then be able to solve the “Keep Connecting” issue.

Thanks for your reply. I made the changes as you suggested, but I still get the “Please wait…” page. Here’s my conf file for reference:

<VirtualHost *:80>
        ServerName beatmap.pmeal.com
        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>

I also added the config.toml like you suggested.

Update: I tried adding the following rule and it worked:

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8501

However, now everything points to the streamlit app, which is not what I wanted. I have my personal website hosted on the same EC2 instance. Is there a way around it?