question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
koenvocommented, Jul 22, 2020

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.

1reaction
koenvocommented, Jul 23, 2020

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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Streamlit behind revese proxy doesn't work when you change ...
I am trying to run streamlit behind reverse proxy. I have following situation which works behind reverse proxy: 1.streamlit hello --server.
Read more >
Behind a Proxy - FastAPI
Having a proxy with a stripped path prefix, in this case, means that you could declare a path at /app in your code,...
Read more >
Deploying Streamlit Applications with Azure App Services
If you wanted to run your Streamlit application in production, the best practice would be to set up a reverse proxy such as...
Read more >
Nginx, fastapi and streamlit in docker - reverse proxy does not ...
I made it work with these nginx config location /spectrum { proxy_pass http://spectrum1:8501/spectrum; proxy_http_version 1.1; ...
Read more >
reverse proxy does not work for streamlit-docker - appsloveworld
I made it work with these nginx config location /spectrum { proxy_pass http://spectrum1:8501/spectrum; proxy_http_version 1.1; proxy_set_header ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found