diff --git a/deploy.sh b/deploy.sh index 43d1b8a..f33e4a6 100755 --- a/deploy.sh +++ b/deploy.sh @@ -212,14 +212,12 @@ restart_and_verify() { # 写入 nginx 配置(--init 与 --sync-nginx 共用的唯一模板来源) +# 模板自带完整 443/证书配置(证书存在时启用),不依赖 certbot --nginx 注入—— +# 这样 --sync-nginx 覆盖配置时不会丢失 HTTPS 段(certbot 注入式配置会被覆盖回 80-only) write_nginx_conf() { - $SUDO tee "${NGINX_CONF}" >/dev/null </dev/null </dev/null 2>&1; then log "未检测到证书,尝试自动申请: ${DOMAIN}" - $SUDO certbot --nginx -d "${DOMAIN}" --non-interactive --agree-tos -m "${CERT_EMAIL}" --redirect \ - || warn "证书申请失败,请检查域名解析与 80 端口;可稍后手动执行 certbot --nginx -d ${DOMAIN}" + $SUDO mkdir -p /var/www/html + if $SUDO certbot certonly --webroot -w /var/www/html -d "${DOMAIN}" --non-interactive --agree-tos -m "${CERT_EMAIL}"; then + log "证书申请成功,写入 443 配置..." + write_nginx_conf + else + warn "证书申请失败,请检查域名解析与 80 端口;成功后重跑: $0 --sync-nginx" + fi else warn "未安装 certbot,跳过证书申请。可手动执行: dnf install certbot python3-certbot-nginx" fi