feat(deploy): 宿主机单 Nginx 方案、compose 覆盖与启动脚本

Made-with: Cursor
This commit is contained in:
whm
2026-03-27 11:15:00 +08:00
parent 2f78fd0d52
commit 38c4c465c5
4 changed files with 209 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# 宿主机 Nginx 单实例部署:启动 api/web/admin/mongo不启动容器 yh_nginx并可选安装站点配置后 reload。
# 用法(在项目根目录):
# chmod +x scripts/start-with-host-nginx.sh
# ./scripts/start-with-host-nginx.sh
#
# 依赖:已安装 Docker Compose、宿主机 Nginx、证书目录 /etc/ssl/yh_web/yuheng.yuxindazhineng.com/
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
echo "==> 启动容器mongo api web admin不启动 compose 内 yh_nginx"
docker compose -f docker-compose.yml -f docker-compose.host-nginx.yml up -d mongo api web admin
echo "==> 若曾用旧方案启动过 yh_nginx可手动停止释放 443 docker rm -f yh_nginx 2>/dev/null || true"
docker rm -f yh_nginx 2>/dev/null || true
VERIFY_ROOT="${VERIFY_ROOT:-$ROOT/verify-root}"
mkdir -p "$VERIFY_ROOT"
CONF_OUT="${NGINX_CONF_OUT:-/etc/nginx/conf.d/yuheng.yuxindazhineng.com.conf}"
TEMPLATE="$ROOT/nginx/yuheng.host.conf"
if [[ ! -f "$TEMPLATE" ]]; then
echo "缺少模板:$TEMPLATE" >&2
exit 1
fi
echo "==> 生成宿主机 Nginx 配置VERIFY_ROOT=$VERIFY_ROOT"
if [[ "${INSTALL_NGINX_CONF:-1}" == "1" ]]; then
if ! command -v sudo >/dev/null 2>&1; then
echo "未找到 sudo请手动执行" >&2
echo " sed \"s|__VERIFY_ROOT__|$VERIFY_ROOT|g\" \"$TEMPLATE\" | sudo tee \"$CONF_OUT\"" >&2
echo " sudo nginx -t && sudo systemctl reload nginx" >&2
exit 0
fi
sed "s|__VERIFY_ROOT__|$VERIFY_ROOT|g" "$TEMPLATE" | sudo tee "$CONF_OUT" >/dev/null
sudo nginx -t
sudo systemctl reload nginx
echo "==> 已写入 $CONF_OUT 并重载 Nginx。请确认 443 仅由宿主机占用: ss -tlnp | grep 443"
else
echo "已跳过安装INSTALL_NGINX_CONF=0。可手动"
echo " sed \"s|__VERIFY_ROOT__|$VERIFY_ROOT|g\" nginx/yuheng.host.conf | sudo tee $CONF_OUT"
echo " sudo nginx -t && sudo systemctl reload nginx"
fi
echo "==> 本机回环端口(宿主机 Nginx 应反代到这些地址,与 nginx/yuheng.host.conf 一致):"
echo " API http://127.0.0.1:8088"
echo " 前台 http://127.0.0.1:9080"
echo " 后台 http://127.0.0.1:9081"