Let's Encrypt证书90天有效期,本文介绍如何配置自动续期,确保网站HTTPS持续有效。
安装Certbot
Ubuntu/Debian
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
CentOS
sudo yum install certbot python3-certbot-nginx -y
申请证书
Nginx方式
sudo certbot --nginx -d example.com -d www.example.com
sudo certbot --manual --preferred-challenges dns certonly -d *.example.com
手动验证方式
sudo certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com
证书存放位置:
- 证书:/etc/letsencrypt/live/example.com/fullchain.pem
- 私钥:/etc/letsencrypt/live/example.com/privkey.pem
配置Nginx
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# SSL配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_prefer_server_ciphers off;
# HSTS
add_header Strict-Transport-Security "max-age=63072000" always;
}
配置自动续期
测试续期
sudo certbot renew --dry-run
设置定时任务
编辑crontab:
sudo crontab -e
添加以下行:
0 3 * * * /usr/bin/certbot renew --quiet --deploy-hook "systemctl reload nginx"
手动续期
sudo certbot renew
常见问题
| 问题 | 解决方案 |
|---|---|
| 续期失败 | 检查防火墙80端口 |
| DNS验证失败 | 确认DNS解析正确 |
| 证书过期 | 立即运行certbot renew |
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)