Having issues serving containerised app from a subdirectory using nginx

Hey there awesome people! :wave:

I have built and containerised a streamlit app and I am trying to serve it from http://myawsome.domain/myapp via ngnix. (I’m taking things slowly, will look into SSL after I get it running).

Thanks to the following topics, I have been able to serve the app from http://myawesome.domain:

but I just cannot serve it from http://myawesome.domain/myapp!

I am pretty new to both Streamlit and nginx, so please bear with me. I am clearly missing something, but I cannot put my finger on it. Therefore, I seek help and guidance from the community :pray:

/etc/nginx/conf.d/app.conf:

server {

	listen 80;
	server_name myawesome.domain;

	# streamlit config
        location /tesla {
		proxy_pass http://container_name:8501/;
	}

	location ^~ /static {
		proxy_pass http://container_name:8501/static/;
	}

	location ^~ /healthz {
		proxy_pass http://container_name:8501/healthz;
	}

	location ^~ /vendor {
		proxy_pass http://container_name:8501/vendor;
	}

	location /stream {
		proxy_pass http://container_name:8501/stream;
		proxy_http_version 1.1;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $host;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_read_timeout 86400;
	}

}

./Dockerfile:

FROM python:3.10-slim

WORKDIR /app

RUN pip install pipenv

COPY Pipfile* .
RUN pipenv install --system --deploy --ignore-pipfile

COPY . /app

CMD ["/bin/bash", "-c", "streamlit run main.py --server.address 0.0.0.0"]

./.streamlit/config.toml

[server]
port = 8501
baseUrlPath = "/myapp"
enableCORS = false

I realised that I have not posted the error the message that I was getting :see_no_evil:

Nevertheless, solved the problem.

Modifed the ngnix configuration to the following:

server {

        listen 80;
        server_name myAwesomeDomain;

        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;

        # streamlit config
        location /myapp {
            location /myapp/healthz {
                proxy_pass http://container_name:8501/healthz;
            }

             location /myapp/stream {
                proxy_pass http://container_name:8501/stream;
           }

           proxy_pass http://container_name:8501;
        }

        location ^~ /static {
                proxy_pass http://container_name:8501/static/;
        }

        location ^~ /vendor {
                proxy_pass http://container_name:8501/vendor;
        }

}

Now I’m a bit uncertain whether this also played a part in it, but I also changed enableCORS to True in pwd/.streamlit/config.toml.

1 Like

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