From 4cd9d3c32a52fd1b8bea652eaeaeb655c389b181 Mon Sep 17 00:00:00 2001 From: xcwang <1366993017@qq.com> Date: Tue, 29 Nov 2022 23:06:15 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=20Proxy=20Nginx=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=20v6=20=E6=94=AF=E6=8C=81=20(closed=20#1289)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev_log/2.2.32/xcwang_202211292306.yaml | 3 +++ script_tools/start_nginx.sh.tpl | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 dev_log/2.2.32/xcwang_202211292306.yaml diff --git a/dev_log/2.2.32/xcwang_202211292306.yaml b/dev_log/2.2.32/xcwang_202211292306.yaml new file mode 100644 index 000000000..dedc5f6fc --- /dev/null +++ b/dev_log/2.2.32/xcwang_202211292306.yaml @@ -0,0 +1,3 @@ +--- +feature: + - "Proxy Nginx 配置 v6 支持 (closed #1289)" diff --git a/script_tools/start_nginx.sh.tpl b/script_tools/start_nginx.sh.tpl index dd20c7016..d0f84e731 100644 --- a/script_tools/start_nginx.sh.tpl +++ b/script_tools/start_nginx.sh.tpl @@ -3,7 +3,7 @@ rm -rf /opt/nginx-portable/; rm -rf /opt/py36/; tar xvf %(nginx_path)s/py36.tgz -C /opt; tar xvf %(nginx_path)s/nginx-portable.tgz -C /opt; -chmod -R 755 /data +timeout 120 chmod -R 755 /data || echo "chmod directory /data failed" user=root group=root #create group if not exists @@ -23,6 +23,24 @@ DNS_LIST=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf) if ! grep -q "nameserver.*127.0.0.1" /etc/resolv.conf; then DNS_LIST+=(127.0.0.1) fi + +ipv6_valid_ip () { + local ip=$1 + if [[ "${ip}" =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then + return 0 + else + return 1 + fi +} +nginx_dns_list=() +for dns_ip in ${DNS_LIST[@]}; do + if ipv6_valid_ip $ip; then + nginx_dns_list+=(["${dns_ip}"]) + else + nginx_dns_list+=("$dns_ip") + fi +done + echo -e " user $user; events { @@ -34,6 +52,7 @@ http { sendfile on; server { listen %(bk_nodeman_nginx_download_port)s; + listen [::]:%(bk_nodeman_nginx_download_port)s; server_name localhost; root %(nginx_path)s; @@ -47,8 +66,9 @@ http { } server { listen %(bk_nodeman_nginx_proxy_pass_port)s; + listen [::]:%(bk_nodeman_nginx_proxy_pass_port)s; server_name localhost; - resolver ${DNS_LIST[@]}; + resolver ${nginx_dns_list[@]}; proxy_connect; proxy_connect_allow 443 563; location / {