Configuration for reverse proxy
bformet opened this issue · 4 comments
Hey 👋, at ESRF beamlines we would like to be able to run multivisor behind a nginx reverse proxy at some specific location.
The nginx config would look like:
location /multivisor/ {
proxy_pass http://localhost:22000/;
}
Thus we would need multivisor ressources to be relative to current path instead of absolute, and/or to have an option to configure the relative webapp root path, like:
-r, --relative-root string webapp relative root (default "/")
Thanks for the great work
Makes sense to me.
Would you be willing to work on a PR?
I am not sure what is the best solution. I guess I prefer a solution that did not involve an extra command line option but if you think it is the best way to go, it is fine by me.
location ^~ /supervisord/
{
proxy_pass http://10.195.14.6:22000/;
}
I have these question, too , I use it behind a nginx proxy. Because I only have one DNS,so Imust use the location path .
The static file can,t access,error code 404.
there is Elastic Kibana manual,it hava some describe about use proxy.Maybe we can refer to.
server.basePath:
Enables you to specify a path to mount Kibana at if you are running behind a proxy. This only affects the URLs generated by Kibana, your proxy is expected to remove the basePath value before forwarding requests to Kibana. This setting cannot end in a slash (/).
I've managed to do this with a custom Dockerfile
with some quick sed
work that seems to work well (using traefik as a reverse-proxy):
$ cat multivisor/Dockerfile
FROM python:3
# last few sed commands needed to run under reverse proxy correctly
# see: https://github.com/tiagocoutinho/multivisor/issues/66
RUN python -m venv venv && \
. ./venv/bin/activate && \
python -m pip install -U pip multivisor[web] 'werkzeug<2.1.0' 'flask==2.1.3' && \
sed -i 's|=/static|=static|g' venv/lib/python3.11/site-packages/multivisor/server/dist/index.html && \
sed -i 's|"/api|"api|g' venv/lib/python3.11/site-packages/multivisor/server/dist/static/js/*.js
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["--bind", "0.0.0.0:22000", "-c", "/multivisor.conf"]
and my entrypoint.sh
looks like
$ cat multivisor/entrypoint.sh
#!/bin/sh
set -e
set -- /venv/bin/multivisor "$@"
echo "$@"
exec "$@"
Ideally, one would mount to /multivisor.conf
in this example, but as you can see, it's only a few sed
replacements to make it work correctly (dropping the absolute path).
EDIT: Doesn't quite work because the Vue
app does some routing as well, and that starts breaking more things...
It's my solution:
- replace path, add prefix
sed -i 's|/static|/multivisor/static|g' /.venv/lib/python3.10/site-packages/multivisor/server/dist/index.html && \
sed -i 's|/api|/multivisor/api|g' /.venv/lib/python3.10/site-packages/multivisor/server/dist/static/js/*.js && \
sed -i 's|path:"/|path:"/multivisor/|g' /.venv/lib/python3.10/site-packages/multivisor/server/dist/static/js/*.js && \
sed -i 's|to:"/|to:"/multivisor/|g' /.venv/lib/python3.10/site-packages/multivisor/server/dist/static/js/*.js
- add nginx conf
location /multivisor {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/multivisor/(.*)$ /$1 break;
proxy_pass http://localhost:22000;
}