diff --git a/certbot 操作步骤.md b/certbot 操作步骤.md new file mode 100644 index 00000000..893ec246 --- /dev/null +++ b/certbot 操作步骤.md @@ -0,0 +1,88 @@ +✅ **`git.i7l.cn` 全链路上线完成**——公网实测:`https://git.i7l.cn/` 正常渲染 Gitea 1.27.1 页面("inscom-git")。`http://` 自动 301 跳转 HTTPS。 + +**手册已落地**:`/root/workspace/letsencrypt/ADD_DOMAIN_GUIDE.md`(与你的运维脚本同目录),以下是核心流程——以后新增任何 `域名 → 后端` 站点,四步搞定(以下全部在 5.20 上以 root 执行,把 `git.i7l.cn` 和 `192.168.5.27:24400` 换成你的新值): + +## 标准四步(示例:git.i7l.cn → 192.168.5.27:24400) + +**前置**:DNSPod 加 A 记录(域名 → 121.46.230.53);确认后端可达 `wget -q -S -O /dev/null http://192.168.5.27:24400/` + +**① 写 80 临时配置**(签证书的前提) +```bash +cat > /etc/nginx/sites-enabled/git.i7l.cn.conf <<'EOF' +server { + listen 80; + server_name git.i7l.cn; + location ^~ /.well-known/acme-challenge/ { + root /var/www/html; + default_type text/plain; + } + location / { + proxy_pass http://192.168.5.27:24400; + } +} +EOF +nginx -t && systemctl reload nginx +``` + +**② 签发证书**(webroot 模式,自动纳入续期) +```bash +certbot certonly --webroot -w /var/www/html -d git.i7l.cn --non-interactive --agree-tos +# 成功标志:Successfully received certificate. +``` + +**③ 写最终配置**(443 + 80 跳转;Git 类服务保留 `client_max_body_size 0`) +```bash +cat > /etc/nginx/sites-enabled/git.i7l.cn.conf <<'EOF' +server { + listen 443 ssl; + server_name git.i7l.cn; + ssl_certificate /etc/letsencrypt/live/git.i7l.cn/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/git.i7l.cn/privkey.pem; + client_max_body_size 0; # Git 大仓库推送;普通站点可删 + location / { + proxy_pass http://192.168.5.27:24400; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_http_version 1.1; # WebSocket(需要时保留) + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } +} +server { + listen 80; + server_name git.i7l.cn; + location ^~ /.well-known/acme-challenge/ { # 勿删!续期依赖 + root /var/www/html; + default_type text/plain; + } + location / { + return 301 https://$host$request_uri; + } +} +EOF +nginx -t && systemctl reload nginx +``` + +**④ 验证** +```bash +curl -sI https://git.i7l.cn/ | head -3 # 期望 200 +curl -sI http://git.i7l.cn/ | head -3 # 期望 301 +certbot certificates | grep -A3 git.i7l.cn # 证书有效期 +``` + +## 关键维护命令 + +```bash +certbot renew --dry-run --cert-name git.i7l.cn # 续期演练(不动真证书) +~/workspace/letsencrypt/list_domain.sh # 列出全部证书 +~/workspace/letsencrypt/delete_domain.sh git.i7l.cn && rm /etc/nginx/sites-enabled/git.i7l.cn.conf && nginx -t && systemctl reload nginx # 删除域名 +``` + +## 两条铁律 + 排障(手册内有完整表格) + +1. **conf 里的 `acme-challenge` location 永远别删**——webroot 自动续期(cron 每日 3 点 `renew.sh` + certbot.timer)依赖它 +2. **Vite 类站点**记得在 `web-next/vite.config.ts` 的 `allowedHosts` 加新域名,且**不要**配 `hmr.clientPort`(同源即可,硬编码端口会导致内网 HMR 疯狂刷新) + +排障速查(403 入口拦截 / PR_CONNECT_RESET 域名被墙等,均来自本次实战)详见 `ADD_DOMAIN_GUIDE.md` 末节。 \ No newline at end of file