#!/bin/bash set -e # ⚠️ 关键:不给默认值,强制在 SAE 控制台配置 # 如果未配置,报错退出(避免使用错误的后端地址) if [ -z "$BACKEND_SERVICE_HOST" ]; then echo "❌ ERROR: BACKEND_SERVICE_HOST environment variable is required!" echo "Please configure it in SAE console with backend internal IP (e.g., 172.17.x.x)" exit 1 fi if [ -z "$BACKEND_SERVICE_PORT" ]; then echo "⚠️ WARNING: BACKEND_SERVICE_PORT not set, using default: 3001" export BACKEND_SERVICE_PORT=3001 fi echo "============================================" echo "Starting Frontend Nginx Service" echo "Backend Service: ${BACKEND_SERVICE_HOST}:${BACKEND_SERVICE_PORT}" echo "Container Timezone: $(cat /etc/timezone)" echo "Current Time: $(date)" echo "============================================" # 使用 envsubst 替换 Nginx 配置中的环境变量 envsubst '${BACKEND_SERVICE_HOST} ${BACKEND_SERVICE_PORT}' \ < /etc/nginx/templates/nginx.conf.template \ > /etc/nginx/nginx.conf # 验证 Nginx 配置 nginx -t # 启动 Nginx exec nginx -g 'daemon off;'