From 605fe2118d9e2cc4aae281701497af613694349b Mon Sep 17 00:00:00 2001 From: d4c00 Date: Mon, 16 Feb 2026 07:52:40 +0800 Subject: [PATCH] fix: use strict IPv4 regex in nginx resolver to prevent crash ### Problem The current logic filters IPv6 addresses by counting colons (NF-1 <= 2). However, compressed IPv6 addresses like `fd00::1` contain only two colons, causing them to be incorrectly identified as IPv4. This leads to an invalid `resolver.conf` and Nginx fails to start with: `[emerg] invalid port in resolver "fd00::1"` Solution Replaced the unreliable colon-counting logic with a strict IPv4 regex: ^[0-9]{1,3}(\.[0-9]{1,3}){3}$. This ensures only valid IPv4 addresses are added, maintaining the script's intent to "ignore ipv6 addresses" without crashing Nginx. Impact Fixes container startup failure on hosts with IPv6 ULA or compressed addresses in /etc/resolv.conf. --- root/etc/s6-overlay/s6-rc.d/init-nginx/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/etc/s6-overlay/s6-rc.d/init-nginx/run b/root/etc/s6-overlay/s6-rc.d/init-nginx/run index 280ce422..9e3ac526 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-nginx/run +++ b/root/etc/s6-overlay/s6-rc.d/init-nginx/run @@ -47,7 +47,7 @@ touch /config/nginx/resolver.conf if ! grep -q 'resolver' /config/nginx/resolver.conf; then RESOLVERRAW=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf) for i in ${RESOLVERRAW}; do - if [[ "$(awk -F ':' '{print NF-1}' <<<"${i}")" -le 2 ]]; then + if [[ "${i}" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then RESOLVER="${RESOLVER} ${i}" fi done