streamlit: Streamlit behind reverse proxy doesn’t work when you change port

Summary

I am trying to run streamlit behind revese proxy doesn’t work when we change port in streamlit.

Type here a clear and concise description of the bug. Aim for 2-3 sentences. When change port in streamlit, and put it behind reverse proxy, front end try to use default port 8501 rather than changed port.

Steps to reproduce

First run streamlit

streamlit hello --server.port=2000

In reverse proxy, if you point to this url. I am seeing almost all calls fails. But Let me show you one example request.

When I look network, I see following request fail. healthz. Issue is, healthz is still ping at original port (8501) which is seen as following as error:

1. Request URL:

http://localhost:8501/healthz

2. Referrer Policy:

no-referrer-when-downgrade

When I copy request as cURL from browser for that request i see following:

  -H 'Accept: application/json, text/plain, */*' \
  -H 'Referer: http://localhost:3000/' \
  -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Mobile Safari/537.36' \
  --compressed

As you can see here, It is pointing to original port (8501) not change port 2000.

Expected behavior:

Expected behavior should be that it request should use port that is provided in cmd not original

Actual behavior:

However, it is pointing to default (original port) 8501.

Debug info

  • Streamlit version: 0.63.0
  • Python version: Python 3.6.9
  • Using PipEnv
  • OS version: Ubuntu 18.04.4 LTS
  • Browser version: brave

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

What reverse proxy do you use? When using nginx you need to make sure you enable websocket support like this:

        location /stream {
            proxy_pass       http://streamlit;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $host;
      }

So the issue is probably the reverse proxy and not streamlit.

It seems it started again with the newest streamlit version.

That’s interesting @kush99993s.

My setup looks like this:


# nginx config

http {

        # ...... some other stuff ....

 	upstream streamlit {
		server 127.0.0.1:56002 fail_timeout=0;
 	}
        server {
            location /stream {
                 proxy_pass       http://streamlit;
                 proxy_http_version 1.1;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection "Upgrade";
                 proxy_set_header Host $host;
            }

             location / {
                 proxy_pass       http://streamlit;
	         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	         proxy_set_header Host $http_host;
	         proxy_redirect off;
             }
     }
}
streamlit run dashboard.py --server.port 56002