From f90e45035985cc6205612016b665a64fc1e0bd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=AD=86?= <2685475410@qq.com> Date: Sat, 10 Oct 2026 01:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(deploy):=20nginx=20=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=87=AA=E5=B8=A6=20443=20=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=20--sync-nginx=20=E8=A6=86=E7=9B=96=E8=AF=81?= =?UTF-8?q?=E4=B9=A6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 原模板仅 80,443 依赖 certbot --nginx 注入,--sync-nginx 整文件覆盖会抹掉注入配置导致证书回退 - 检测 /etc/letsencrypt/live/<域名>/ 证书存在时自动启用 443,80 仅留 ACME 验证与 301 跳转 - certbot 改用 certonly --webroot,不再改写 nginx 配置;反代 location 抽取为 80/443 共享段 --- deploy.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 9 deletions(-) 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