MLflowをnginxのreverse-proxyからforwardして動かす時にsubpathを用いる設定手順
このエントリでは、
nginxのreverse-proxyの後ろで、MLflowを動かすときの設定メモを残しておきます。
MLflowのセットアップは、以下の手順で行った想定で記載します。
UbuntuLinuxにMLflowをセットアップする手順
https://takemikami.com/2024/0319-ubuntulinuxmlflow.html
試した環境:
- Ubuntu Linux 22.04.3
- nginx 1.18.0
- MLflow 2.11.1
MLflowでsubpathを有効にする
http://localhost:5000/
のようなURLで利用しているMLflowを、http://localhost:5000/mlflow/
のようなsubpathで利用できるように、
起動時に--static-prefix
オプションを指定します。
サービスの設定ファイルにオプションを追記します。
/etc/systemd/system/mlflow.service
[Unit]
Description=MLflow
After=syslog.target
After=network.target
[Service]
RestartSec=2s
Type=simple
User=mlflow
Group=mlflow
WorkingDirectory=~
ExecStart=/var/lib/mlflow/venv/bin/mlflow server --host 0.0.0.0 --port 5000 --static-prefix /mlflow --backend-store-uri /var/lib/mlflow/.mlflow
Restart=always
Environment=VIRTUAL_ENV=/var/lib/mlflow/venv
Environment=PATH=/var/lib/mlflow/venv/bin
[Install]
WantedBy=multi-user.target
設定ファイルを変更したら、以下のようにリロード・再起動します。
$ sudo systemctl daemon-reload
$ sudo service mlflow restart
これで、http://localhost:5000/mlflow/
のようなURLでアクセスできるようになります。
nginx側のreverse-proxy設定
nginxからmlflowにforwardするように設定します。
nginxのインストール方法によってファイルは異なりますが、/etc/nginx/sites-enabled/default
などのファイルに、
次のような記載を追記て、nginxを再起動します。
/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server;
※途中省略※
location /mlflow/ {
proxy_pass http://localhost:5000/mlflow/;
proxy_set_header X-Forwarded-Proto $x_scheme;
proxy_set_header X-outside-url $x_scheme://$http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
以上。