32 lines
706 B
Bash
32 lines
706 B
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
# 生成 nginx htpasswd
|
|
if [ -z "$NGINX_USER" ] || [ -z "$NGINX_PASSWORD" ]; then
|
|
echo "❌ 未设置 NGINX_USER 或 NGINX_PASSWORD,拒绝启动"
|
|
exit 1
|
|
fi
|
|
echo "🔐 生成访问密码..."
|
|
htpasswd -bc /etc/nginx/.htpasswd "$NGINX_USER" "$NGINX_PASSWORD"
|
|
|
|
# 后台启动 Next.js
|
|
echo "🚀 启动 Next.js..."
|
|
pnpm start &
|
|
|
|
# 等待 Next.js 就绪
|
|
echo "⏳ 等待 Next.js 就绪..."
|
|
MAX_WAIT=60
|
|
WAITED=0
|
|
while [ $WAITED -lt $MAX_WAIT ]; do
|
|
if wget -q --spider http://localhost:3000 2>/dev/null; then
|
|
echo "✅ Next.js 已就绪 (${WAITED}s)"
|
|
break
|
|
fi
|
|
sleep 1
|
|
WAITED=$((WAITED + 1))
|
|
done
|
|
|
|
# 前台启动 nginx
|
|
echo "🌐 启动 nginx..."
|
|
exec nginx -g 'daemon off;'
|