← 返回博客

Ubuntu 上用 Certbot 给 Nginx 配 HTTPS

Let's Encrypt 申请失败、续期挂掉、以及 80 端口被占用时的处理步骤。

TensorView Lab · 2026-09-03

前置条件

  • 域名 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/tcp

DNS 未生效

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。

也可以试试 TensorView 小工具集合