refactor(deploy): ?????????? Nginx ????

Made-with: Cursor
This commit is contained in:
whm
2026-03-27 11:55:00 +08:00
parent 38c4c465c5
commit 0980d1fa9c
6 changed files with 87 additions and 100 deletions

View File

@@ -276,7 +276,7 @@ bash "$ROOT/scripts/merge-server-env-from-example.sh" "$ROOT" || true
echo ""
echo "[2/3] 重新构建并启动..."
# 宿主机 9527 常被 sshd 占用compose 必须使用 8088 且 api 不映射宿主机端口
# 宿主机 9527 常被 sshd 占用compose 内 API 须为 8088。若宿主机 Nginx 已运行docker-compose.host-nginx.yml 会把 api/web/admin 绑到本机回环供反代。
if grep -q '9527' "$ROOT/docker-compose.yml" 2>/dev/null; then
echo "错误: 当前 docker-compose.yml 仍含 9527会与 sshd 冲突导致启动失败。请以 Gitea 为准拉取最新代码后再执行本脚本:" >&2
echo " git fetch origin && git reset --hard origin/master" >&2
@@ -354,21 +354,18 @@ elif [ -f "$ROOT/nginx/$NGINX_DOMAIN/fullchain.pem" ] && [ -f "$ROOT/nginx/$NGIN
run_sudo chmod 644 "$NGINX_SSL_DIR/fullchain.pem"
run_sudo chmod 600 "$NGINX_SSL_DIR/privkey.pem"
fi
compose_cmd down 2>/dev/null || true
compose_cmd up -d --force-recreate
# shellcheck disable=SC1091
. "$ROOT/scripts/lib-yh-compose-deploy.sh"
# 先停掉本项目 Compose 栈(不操作宿主机 nginx 服务);再按宿主机 Nginx 是否在线拉起容器
yh_compose_down
yh_compose_up
# 可选web/promotion/视频发布 -> data/uploads + MongoDB须 server/.env 中 YH_IMPORT_PROMOTION_SITE_ID
bash "$ROOT/scripts/run-promotion-import-on-deploy.sh" "$ROOT"
echo ""
echo "[3/3] 证书与宿主机 Nginx(可选..."
NGINX_CONF_NAME="${NGINX_DOMAIN}.conf"
if [ -f "$ROOT/nginx/$NGINX_CONF_NAME" ]; then
run_sudo cp -f "$ROOT/nginx/$NGINX_CONF_NAME" /etc/nginx/conf.d/ 2>/dev/null || true
if run_sudo nginx -t 2>/dev/null; then
run_sudo systemctl reload nginx 2>/dev/null && echo "宿主机 Nginx 已重载." || true
fi
fi
echo "[3/3] 宿主机 Nginx 站点(仅当 systemctl 显示 Nginx 已运行时写入 yuheng.host.conf 并重载,不执行 start/stop..."
yh_install_host_nginx_site_conf
echo ""
echo "完成. 对外仅 443反代: https://$NGINX_DOMAIN"