フロントエンドは Nginx を使って Proxy し、バックエンドで Streamlit を動作させる場合、例えば Nginx 側は /etc/nginx/conf.d/default.conf
を以下のように設定することが出来ます。 location /app
内で proxy_pass http://127.0.0.1:8501;
を指定することにより、http://ADDRESS/app/
へのリクエストは Nginx で Proxy され、ローカルホストの 8501/TCP で動作している Streamlit アプリケーションへ転送されます。
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location /app {
proxy_pass http://127.0.0.1:8501;
proxy_redirect http:// https://;
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 を起動すると、Nginx 経由で正しく Streamlit アプリケーションへアクセスすることが出来ません。
streamlit run app.py
このディレクトリ構造を前提とすると場合、Streamlit の引数に --server.baseUrlPath /app/
を指定する必要があります。
streamlit run app.py --server.address=127.0.0.1 --server.port 8501 --server.baseUrlPath /app/
--server.baseUrlPath
オプションについては Configuration で下記にように記載されています。
The base path for the URL where Streamlit should be served from.
Default: ""
フォーラムでは Deploying to a folder / path on server で言及されています。
コメント