From 378b6f4a55e91b75bd912d538c1fbad87ae346cb Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Sat, 28 May 2022 18:57:19 +0100 Subject: [PATCH] =?UTF-8?q?INFRA-61=20=E2=80=93=20fix=20SSL=20proxy=20redi?= =?UTF-8?q?rect=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- secrets_entrypoint.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/secrets_entrypoint.sh b/secrets_entrypoint.sh index fb3d477..f54397f 100755 --- a/secrets_entrypoint.sh +++ b/secrets_entrypoint.sh @@ -12,5 +12,20 @@ fi # Load the S3 secrets file contents into the environment variables export $(aws s3 cp s3://${SECRETS_BUCKET_NAME}/secrets - | grep -v '^#' | xargs) +# Fix redirect loop behind ALB. https://forum.mautic.org/t/mautic-redirect-loop/16990/3 +INDEX_FILE="/var/www/html/index.php" +NEW_LINE="\$_SERVER[\"HTTPS\"] = \"on\";\n" +if test -f "$INDEX_FILE"; then + if grep -q "$NEW_LINE" "$INDEX_FILE"; then + echo "SSL modification already in place" + else + # Existing line regex based on https://github.com/mautic/mautic/blob/4.x/index.php + sed -i -e 's/(<\?php)/$1\n\$_SERVER["HTTPS"] = "on";/g' "$INDEX_FILE" + echo "SSL modification applied" + fi +else + echo "No index.php – no SSL modification" +fi + # Call the normal Mautic entrypoint script then the e.g. start Apache CMD (argument to entrypoint). /entrypoint.sh "$@"