From 9b0eb083b4e5b3155093744207ae4495fff4ee1f Mon Sep 17 00:00:00 2001 From: sbgap Date: Mon, 14 Sep 2026 13:43:58 +0200 Subject: [PATCH] fix: change redirects to remember base path --- config/templates/app/nginx.conf.j2 | 7 +++++-- docker-entrypoint.sh | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config/templates/app/nginx.conf.j2 b/config/templates/app/nginx.conf.j2 index 0e59139..52ad5e7 100644 --- a/config/templates/app/nginx.conf.j2 +++ b/config/templates/app/nginx.conf.j2 @@ -46,7 +46,10 @@ http { access_log /dev/stdout main; - location {{ env.FRONTEND_BASE_URL }}api { + absolute_redirect off; + + + location {{ env.FRONTEND_BASE_URL }}api/ { include /etc/nginx/uwsgi_params; uwsgi_pass backend; @@ -66,7 +69,7 @@ http { {% if env.FRONTEND_BASE_URL != '/' -%} location / { - return 301 {{ env.FRONTEND_BASE_URL }}; + return 301 {{ env.FRONTEND_BASE_URL[:-1] }}$request_uri; } {%- endif %} } diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b63b524..ee39e59 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -4,7 +4,6 @@ JINJA2="import os, sys, jinja2; sys.stdout.write(jinja2.Template(sys.stdin.read( ALERTA_CONF_FILE=${ALERTA_CONF_FILE:-/app/alerta.conf} ALERTA_SVR_CONF_FILE=${ALERTA_SVR_CONF_FILE:-/app/alertad.conf} -ALERTA_WEB_CONF_FILE=/web${FRONTEND_BASE_URL}config.json NGINX_CONF_FILE=/app/nginx.conf UWSGI_CONF_FILE=/app/uwsgi.ini SUPERVISORD_CONF_FILE=/app/supervisord.conf @@ -17,6 +16,14 @@ ADMIN_USER=${ADMIN_USERS%%,*} ADMIN_PASSWORD=${ADMIN_PASSWORD:-alerta} MAXAGE=${ADMIN_KEY_MAXAGE:-315360000} # default=10 years +# Make sure that FRONTEND_BASE_URL ends with a / +if [[ "${FRONTEND_BASE_URL: -1}" != "/" ]]; then + if [ $INIT_LOG = true ]; then echo "# Fixed FRONTEND_BASE_URL by adding a '/' at the end"; fi + export FRONTEND_BASE_URL=${FRONTEND_BASE_URL}/ +fi + +ALERTA_WEB_CONF_FILE=/web${FRONTEND_BASE_URL}config.json + # Generate minimal server config, if not supplied if [ ! -f "${ALERTA_SVR_CONF_FILE}" ]; then if [ $INIT_LOG = true ]; then echo "# Create server configuration file."; fi