From e37546b795da5ec240bb2d93483b9873804aea0a Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Wed, 26 Feb 2025 06:21:05 +0000 Subject: [PATCH] Fix (docker): Ensure nginx does not listen on ipv6 in ipv4-only environments The official nginx images do not listen on ipv6, very likely to avoid nginx crashing on startup in ipv4-only environments: ``` docker run --rm -it nginx:alpine cat /etc/nginx/conf.d/default.conf | grep -i listen ``` Hence, we simply need to detect whether ipv6 is disabled, and not listen on ipv6 if ipv6 is disabled in the kernel or in the container. --- .docker/release/files/entrypoint.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.docker/release/files/entrypoint.sh b/.docker/release/files/entrypoint.sh index 75e82d729..c0ed7df0c 100755 --- a/.docker/release/files/entrypoint.sh +++ b/.docker/release/files/entrypoint.sh @@ -9,6 +9,12 @@ UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-25M} MEMORY_LIMIT=${MEMORY_LIMIT:-128M} SECURE_COOKIES=${SECURE_COOKIES:-true} +# Disable listening on ipv6 for ipv4-only environments, or nginx will fail to start +if ! ip a | grep 'inet6 ' > /dev/null; then + echo "[INFO] ipv6 is disabled. Configuring nginx to not listen on ipv6" + sed -i '/listen \[::\]:/d' /etc/nginx/nginx.conf +fi + # Set attachment size limit sed -i "s//$UPLOAD_MAX_SIZE/g" /usr/local/etc/php-fpm.d/php-fpm.conf /etc/nginx/nginx.conf sed -i "s//$MEMORY_LIMIT/g" /usr/local/etc/php-fpm.d/php-fpm.conf