网络与DNS3 分钟阅读更新于 2026-04-30
使用Let's Encrypt获取免费TLS证书
安装certbot,签发证书,并自动续期——您的网站在5分钟内即可使用HTTPS。
Let's Encrypt签发免费的90天TLS证书。certbot工具自动化签发、配置和续期。对于典型的nginx设置,整个过程只需5分钟。
安装certbot
在Ubuntu 22.04+上: code:apt install certbot python3-certbot-nginx -y
在AlmaLinux/Rocky上: code:dnf install certbot python3-certbot-nginx -y
运行certbot向导
code:certbot --nginx -d example.com -d www.example.com
它会提示输入电子邮件(用于过期警告)并接受服务条款。然后签发证书、配置nginx并重新加载服务。
验证自动续费
code:certbot renew --dry-run
certbot包安装一个systemd定时器,每天运行两次,并在到期前30天内续订任何证书。无需进一步操作。
可选:加强TLS
编辑您的nginx服务器块以添加现代TLS配置:仅TLS 1.2/1.3、强密码套件、HSTS头。使用https://ssl-config.mozilla.org/生成经过测试的配置。