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 does not work correctly behind a reverse proxy if a trailing slash is omitted

See original GitHub issue

Summary

When Streamlit is behind a reverse proxy, it won’t work if a trailing slash is not included.

Steps to reproduce

Setup nginx with the following nginx.conf:

worker_processes  1;

events {
    worker_connections 1024;
}

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    server {
        listen 5000;
        server_name localhost;

        location /my_prefix/another {
            rewrite /my_prefix/another/(.*) /$1  break;
            rewrite /my_prefix/another /  break;
            proxy_pass http://localhost:8501;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }
}

Run streamlit on localhost.

Access streamlit at http://localhost:5000/my_prefix/another

Expected behavior:

You can access Streamlit

Actual behavior:

Not able to access Streamlit. Path to static resources are broken. They miss a part of the rewrite rule: Screen Shot 2020-02-24 at 2 16 38 PM

Additional information

  • Addign a trailing slash as http://localhost:5000/my_prefix/another/ fixes this problem.
  • This may show up with other reverse proxy than nginx.
  • A quick fix is to add a redirect rule to the address with the trailing slash.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

3reactions
sorenwackercommented, Dec 10, 2020

Same problem. Even when serving at / I just get a blank page.

0reactions
admo1commented, Aug 30, 2022

I also have this issue when using K8s ingress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing Streamlit through reverse proxy results in "Please ...
I'm having troubles deploying a streamlit application: The site can be accessed w/o problems when using its original port (8080) but not when ......
Read more >
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 >
Media path for nginx? - Deploying Streamlit
I would be curious to see if there is any problem in the way we ... and with and without trailing slash at...
Read more >
How to use Streamlit with Nginx?
The nginx configuration here helped me: Host streamlit app at a subfolder . The problem was that I was redirecting IP/app to IP:<streamlit-port> ......
Read more >
Using streamlit behind a reverse proxy
I think the problem you're hitting is related to the path user/streamlit . Right now Streamlit apps need to be at / ....
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