From 46277dfdb4b868d0a4572cd08dd73de74c9e450d Mon Sep 17 00:00:00 2001 From: jingrow Date: Fri, 8 Aug 2025 07:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtraefik=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=87=8C=E9=9D=A2host=5Fip=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install_jsite.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/install_jsite.sh b/install_jsite.sh index 4022af6..cb1c0cb 100755 --- a/install_jsite.sh +++ b/install_jsite.sh @@ -53,9 +53,10 @@ get_optimal_host_ip() { # 测试内网IP是否可达 if ping -c 2 -W 1 "$private_ip" >/dev/null 2>&1; then host_ip="$private_ip" - log_success "使用内网IP: $host_ip" + # 注意:这里不输出日志,避免污染返回值 else - log_warning "内网IP不可达: $private_ip" + # 注意:这里不输出日志,避免污染返回值 + : fi fi @@ -63,17 +64,17 @@ get_optimal_host_ip() { if [ -z "$host_ip" ]; then if [ -n "$PUBLIC_IP" ]; then host_ip="$PUBLIC_IP" - log_info "使用指定的公网IP: $host_ip" + # 注意:这里不输出日志,避免污染返回值 else # 尝试自动获取公网IP local auto_public_ip=$(curl -s --max-time 5 ifconfig.me 2>/dev/null || curl -s --max-time 5 ipinfo.io/ip 2>/dev/null) if [ -n "$auto_public_ip" ]; then host_ip="$auto_public_ip" - log_info "自动获取公网IP: $host_ip" + # 注意:这里不输出日志,避免污染返回值 else # 最后回退:使用第一个可用IP host_ip=$(hostname -I | awk '{print $1}') - log_warning "使用备用IP: $host_ip" + # 注意:这里不输出日志,避免污染返回值 fi fi fi @@ -637,6 +638,14 @@ create_env_file() { # 智能IP选择:优先使用内网IP,没有内网IP时使用公网IP(与traefik配置保持一致) local host_ip=$(get_optimal_host_ip) + # 输出IP选择结果 + if [[ "$host_ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + log_success "使用IP地址: $host_ip" + else + log_warning "IP地址格式异常: $host_ip" + return 1 + fi + # 构建PUBLIC_SITE_URL(优先使用内网IP,没有内网IP时使用公网IP) local public_site_url="http://$host_ip:$project_port" @@ -1109,6 +1118,14 @@ create_traefik_website_config() { # 智能IP选择:优先使用内网IP,没有内网IP时使用公网IP local host_ip=$(get_optimal_host_ip) + # 输出IP选择结果 + if [[ "$host_ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + log_success "使用IP地址: $host_ip" + else + log_warning "IP地址格式异常: $host_ip" + return 1 + fi + # 生成Host规则 local host_rule=$(generate_host_rule "$SITE_URL")