在ec2 nginx子域上运行streamlit应用程序

w51jfk4q  于 2023-08-03  发布在  Nginx
关注(0)|答案(1)|浏览(174)

我在使用nginx和tmux的单个EC2服务器上在2个不同的子域上运行2个不同的streamlit应用程序时遇到了困难。

第一阶段:我第一次尝试只运行1个应用程序成功,我的nginx配置如下:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                proxy_pass http://localhost:8501;
                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;
        } 
}

字符串

第二阶段:然而,当我尝试运行2个不同的streamlit应用程序时。它不起作用。我的nginx配置文件如下:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location /app {
                proxy_pass http://localhost:8501;
                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;
        }
}

        location /upload {
                proxy_pass http://localhost:8502;
                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;
        }
}


当我深入浏览器控制台时,以下2个文件被报告为不可用。

  1. 404(Not Found)页面没有找到
  2. 404(Not Found)404(Not Found)
    这两个文件实际上是为streamlit安装的site-packages。

第三阶段:我试图通过将根目录传递到相应的位置来修复上述错误。以及在位置URL后添加斜杠。更新配置文件如下:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location /app/ {
                root /home/ubuntu/.local/lib/python3.8/site-packages/streamlit;
                proxy_pass http://localhost:8501;
                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;
        }

        location /upload/ {
                root /home/ubuntu/.local/lib/python3.8/site-packages/streamlit;
                proxy_pass http://localhost:8502;
                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;
        }
}


不幸的是,我仍然面临问题。我想到了一个稍微不同的例子,如下:

  1. 404 Not Found(未找到)
  2. 404 Not Found(未找到)
wnavrhmk

wnavrhmk1#

你可以加上

--server.baseUrlPath=myapp

字符串
到streamlit run args,应用程序将运行在,例如。

http://0.0.0.0:8080/myapp

相关问题