Files
go-sms-V2/certbot 操作步骤.md
Tory ddbfd5b399
ci / test (push) Waiting to run
ci / build (push) Blocked by required conditions
ci / web-test (push) Waiting to run
ci / deploy-dev (push) Blocked by required conditions
添加 certbot 操作步骤.md
2026-11-18 10:49:13 +08:00

88 lines
3.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
✅ **`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` 末节。