From b7ff7602f63767aaab10a15ab9f95f207e95d144 Mon Sep 17 00:00:00 2001 From: u00lipp Date: Thu, 30 Oct 2025 11:03:09 +0100 Subject: [PATCH] fix: nginx config --- deploy/docker-entrypoint.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/deploy/docker-entrypoint.sh b/deploy/docker-entrypoint.sh index c458434..2de8bc1 100644 --- a/deploy/docker-entrypoint.sh +++ b/deploy/docker-entrypoint.sh @@ -1,29 +1,38 @@ #!/bin/sh set -e -SERVER_NAME="${SERVER_NAME:-$(hostname -f 2>/dev/null || hostname)}" -export SERVER_NAME - -# Render vhost ONLY into http.d so it's inside http{} context -if [ -f /etc/nginx/templates/default.conf.template ]; then - envsubst '$SERVER_NAME' < /etc/nginx/templates/default.conf.template > /etc/nginx/http.d/default.conf +# Ensure SERVER_NAME is set +if [ -z "$SERVER_NAME" ]; then + echo "[entrypoint] SERVER_NAME is not set. Using default value: localhost" + SERVER_NAME="localhost" else - echo "[entrypoint] ERROR: missing /etc/nginx/templates/default.conf.template" >&2 - exit 1 + echo "[entrypoint] Using SERVER_NAME=$SERVER_NAME" fi -# Add basic authentication if enabled +# Prepare BASIC_AUTH_DIRECTIVES if [ "$ENABLE_BASIC_AUTH" = "true" ]; then echo "[entrypoint] Enabling basic authentication..." if [ -f /etc/nginx/htpasswd ]; then - # Use sed to append basic auth directives inside the location block - sed -i '/location \/ {/a \\t\tauth_basic "Restricted Content";\n\t\tauth_basic_user_file /etc/nginx/htpasswd;' /etc/nginx/http.d/default.conf + BASIC_AUTH_DIRECTIVES=$(cat <&2 exit 1 fi else echo "[entrypoint] Basic authentication is disabled." + BASIC_AUTH_DIRECTIVES="" +fi + +# Render the NGINX configuration +if [ -f /etc/nginx/templates/default.conf.template ]; then + envsubst '$SERVER_NAME,$BASIC_AUTH_DIRECTIVES' < /etc/nginx/templates/default.conf.template > /etc/nginx/http.d/default.conf +else + echo "[entrypoint] ERROR: missing /etc/nginx/templates/default.conf.template" >&2 + exit 1 fi # Test nginx configuration