Running Streamlit on AWS EC2 Linux ubuntu with Nginx Server Issues

{{UPDATE:
I figured out the problem. I had the NGINX file set on the “external” IP:8501 and not the Network IP:8501, equivalent to localhost:8501. This issue was figured out.

However, note that this setup has proven to work great - so anyone setup to run their app under an SSL subdomain, this has been working fine.}}

I’m running an nginx on an AWS EC2 linux ubuntu instance. I have the location file setup and its been running fine. however, I ran a streamlit install update and now all of a sudden it isn’t. What is curious is that the error I’m getting has to do with a favicon from the looks of it. There is no favicon.ico file in the app directory - I do not know why it keeps doing this, but it gives a 504 Gateway timeout error.

Here is the server file details (cleaned of identifying info):

  server {
      listen 80;
      server_name subdo.name.app;
      #redirect HTTP to HTTPs
      return 301 https://$host$request_uri;
  }
  
  server {
      listen 443 ssl;
      server_name subdo.name.app;  # Replace with your actual domain name
  
      # SSL configuration
      ssl_certificate /path/to/fullchain.pem; # managed by Certbot
      # Path to your SSL certificate
      ssl_certificate_key /path/to/privkey.pem; # managed by Certbot
      # Path to your private key
  
       location / {
	  # Basic authentication configuration
          auth_basic "Restricted Content";  # This is the message shown in the login prompt
          auth_basic_user_file /path/to/.htpasswd;  # Path to the file containing the username and password
  
          proxy_pass http://XX.XXX.XX.XXX:8501;
          proxy_http_version 1.1;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
      }
  }

Here is what the nginx error log is showing:

  2024/05/07 11:12:23 [error] 1991#1991: *7 upstream timed out (110: Unknown error) while connecting to upstream, client: XXX.XXX.X.X.X, server: subdo.name.app, request: "GET / HTTP/1.1", upstream: "http://XX.XXX.XX.XXX:8501/", host: " subdo.name.app"
  2024/05/07 11:13:23 [error] 1991#1991: *7 upstream timed out (110: Unknown error) while connecting to upstream, client: XXX.XXX.X.X.X, server: subdo.name.app, request: "GET /favicon.ico HTTP/1.1", upstream: "http://XX.XXX.XX.XXX:8501/favicon.ico", host: " subdo.name.app", referrer: "https:// subdo.name.app/"

again, I want to emphasize that this was working just fine the last few days. This morning the server was down, so I rebooted it - everything is back running, nginx is up and status is good. I am running the app inside of a tmux session and detaching so it stays live - all of that is working - but the above are the relevant factors pertinent to the issue. Here is the content of my requirements.txt file used to install everything this morning:

pandas==2.2.0
streamlit>=1.31.0
openpyxl~=3.1.2
sqlalchemy~=2.0.27
python-dotenv~=1.0.1
pandasql~=0.7.3
numpy~=1.26.3
boto3==1.34.54
botocore==1.34.54
openpyxl==3.1.2
Pillow==10.2.0
tinydb==4.8.0
XlsxWriter==3.2.0
werkzeug

Note that there was a file permissions issue previously - that has been resolved. I can’t think of anything else to include regarding this.

A few other points on this.

  1. I’ve not previously had to have a .streamlit directory with a config.toml - its been working without such a thing up till now.
  2. It is running fine when I go to http://XXX.XX.X.XXX:8501 and has no errors reporting in the terminal when I run it.
  3. AWS Security Group is setup to permit traffic appropriately via HTTP and HTTPS, and the SSL certificate are good to go.
  4. The only thing I did this morning was run a pip install of the requirements.txt file, none of which made a change as all libraries were already installed. I was just testing the procedure for relaunching the app on a new server, using the existing one.
  5. The app is being run in a tmux session that I then detach from once its running - again, no issues running it and the 8501 port shows it running fine without any error reporting.

Please provide any guidance/direction on how to resolve this problem - my team uses this app daily for their work and its dead right now.

Hi @WilsonCampbell-BMOC

Sorry to hear about this. Just for troubleshooting purposes, can you let us know if downgrading streamlit helps to resolves the issue, so that we can know if this is caused by the recent release.

Yes, I have tried reverting to previous versions of streamlit and I’m getting the same result. The most recent upgrade as of 5/10/2024 and the version prior to it. It was running under the version prior to it before I rebooted the server due to it going down because of an unknown issue. This has been occurring frequently, and I had gotten used to rebooting each morning, running streamlit, and being back in action (think I’ve got too many users and the AWS EC2 micro instance isn’t enough, so I upgraded and it worked on that one also).

At any rate, after rebooting and running it as per normal, it stopped being available. I would get the 504 error. I decided to do the upgrade, and the problem persisted.

{{UPDATE:
I figured out the problem. I had the NGINX file set on the “external” IP:8501 and not the Network IP:8501, equivalent to localhost:8501. This issue was figured out.

So make sure you use the http://localhost:8501 - replacing localhost with the IP it displays when you run it in the tmux session.

Note that this setup has proven to work great - so anyone setup to run their app under an SSL subdomain, this has been working fine, sans my dummy mistake explained in great detail here.}}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.