1. 查看证书到期时间
(1) 定位证书文件
在 /root
目录中查找证书文件(通常为 .crt
、.pem
或 .cert
扩展名):
sudo ls -l /root | grep -E '\.(crt|pem|cert)$'
(2) 查看证书过期时间
使用 OpenSSL 检查证书(替换 your-cert.pem
为实际文件名):
sudo openssl x509 -enddate -noout -in /root/your-cert.pem
-
输出示例:
notAfter=Dec 31 23:59:59 2024 GMT
即证书将在 2024年12月31日 过期
(3) 查看完整证书信息(可选)
sudo openssl x509 -text -noout -in /root/your-cert.pem
重点检查:
-
Not Before
:生效时间 -
Not After
:过期时间 -
Subject Alternative Name
:覆盖的域名
2. 续订证书(分两种情况)
▶ 情况A:证书由 Certbot 创建(但未识别)
即使 certbot certificates
无输出,可能是配置问题,尝试手动续订:
# 先查找关联的证书配置文件 sudo find /etc/letsencrypt/renewal/ -name "*.conf" # 强制续订所有证书 sudo certbot renew --force-renewal # 重启 Web 服务 sudo systemctl reload nginx # 或 apache2
▶ 情况B:手动获取的证书(需重新申请)
适用于非 Certbot 申请的证书(如手动购买上传):
-
向 CA 重新申请证书
-
登录证书颁发机构(如 Let’s Encrypt、阿里云SSL等)
-
按流程申请新证书(通常需验证域名所有权)
-
-
替换旧证书
下载新证书文件到/root
,然后:# 备份旧证书 sudo cp /root/your-cert.pem /root/your-cert.pem.bak sudo cp /root/your-private.key /root/your-private.key.bak # 替换为新证书 sudo mv ~/下载/new-cert.pem /root/your-cert.pem sudo mv ~/下载/new-key.key /root/your-private.key
-
重启 Web 服务生效
# Nginx sudo nginx -t && sudo systemctl reload nginx # Apache sudo apachectl configtest && sudo systemctl reload apache2
3. 配置自动续订(推荐)
(1) 对于 Certbot 证书
创建定时任务每月检查续订:
# 编辑 crontab sudo crontab -e
添加以下内容(每天 2:30 自动续订):
30 2 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload nginx"
(2) 对于手动证书
建议改用 Certbot 自动化管理(以 Nginx 为例):
# 安装 Certbot sudo apt update sudo apt install certbot python3-certbot-nginx # 申请新证书(自动配置) sudo certbot --nginx -d your-domain.com # 验证自动续订 sudo certbot renew --dry-run
关键命令总结
操作 | 命令 |
---|---|
查找证书文件 | sudo ls -l /root | grep -E '\.(crt|pem|cert)$' |
查看到期时间 | sudo openssl x509 -enddate -noout -in /root/cert.pem |
强制续订 Certbot 证书 | sudo certbot renew --force-renewal |
测试 Nginx 配置 | sudo nginx -t |
重载 Nginx | sudo systemctl reload nginx |
设置自动续订 | sudo crontab -e 添加 Certbot 任务 |
注意:
替换所有
your-cert.pem
、your-domain.com
为实际名称续订后务必 重启 Web 服务 使新证书生效
私钥文件(
.key
)需严格保密,权限设置为600
:sudo chmod 600 /root/your-private.key
文章链接:https://www.wuyanshuo.cn/19560.html
更新时间:2025年08月18日
本站资源均为两层压缩,第一层7z(后缀若为wys,请自行修改为7z)有解压密码;第二层zip或cbz,无解压密码,可直接使用漫画类软件程序查看;详情可参考解压教程。
本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:service@wuyanshuo.cn我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读无言说网络服务协议。