前置条件
- 域名 A 记录已指向服务器公网 IP
- 安全组放行 80/443
- Nginx 已有对应
server_name的 server 块
sudo apt update
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com常见失败
Connection refused on validation
80 端口没开,或被其它进程占用:
sudo ss -lntp | grep ':80'
sudo ufw allow 80/tcp
sudo ufw allow 443/tcpDNS 未生效
dig +short example.com
curl -I http://example.com续期
sudo certbot renew --dry-run定时任务一般由包安装自动加好;若手工装过,检查:
systemctl list-timers | grep certbot小提示
测试环境用 staging 避免触发限速:
sudo certbot --nginx --staging -d example.com配好 HTTPS 后,记得 proxy_set_header X-Forwarded-Proto $scheme;,否则上游以为自己还在 HTTP。