证书失效后浏览器可以看到错误提示,以及证书过期时间。
排查服务器证书续期配置
1. 证书未正确安装或配置
确保在阿里云服务器上部署的 Let’s Encrypt 证书已经正确安装。你可以通过以下步骤确认:
- 使用命令
sudo certbot certificates
检查证书是否正确安装。 - 确认 Web 服务器(如 Nginx 或 Apache)配置了正确的证书路径。
2. 证书没有成功自动续期
即使开启了自动续期,可能由于配置问题导致续期失败。可以手动尝试续期证书:
- 运行
sudo certbot renew --dry-run
来模拟续期过程,检查是否有任何错误。 - 如果一切正常,可以手动执行续期
sudo certbot renew
,并重启 Web 服务器(例如:sudo systemctl restart nginx
或sudo systemctl restart apache2
)。
3. 浏览器缓存问题
有时浏览器会缓存旧的证书,导致即使服务器上已经更新证书,浏览器仍然提示证书过期。可以尝试:
- 清理 Chrome 浏览器缓存:
Ctrl + Shift + Delete
,选择 “清除浏览数据”。 - 强制刷新网页:按
Ctrl + F5
进行强制刷新。
4. 检查证书链
可能是证书链(包括中间证书)不完整,导致浏览器无法识别。你可以通过以下命令检查:
- 使用命令
openssl s_client -connect yourdomain.com:443 -showcerts
来查看当前服务器的证书链。 - 确保在服务器配置文件中(如 Nginx 的
ssl_certificate
)包含完整的证书链。
5. 证书覆盖问题
如果曾经手动配置了证书,且没有正确覆盖,可能导致旧证书仍在使用。可以通过重新配置 Web 服务器的证书路径,确保指向新的证书文件。
6. 时间问题
确保服务器的时间是准确的,使用 date
命令查看服务器的时间,确认没有时间错误(尤其是时区问题)。
如果这些方法都无法解决问题,可以提供更多的详细信息(如使用的 Web 服务器、证书续期日志等),我可以进一步帮助你分析问题。
测试自动续期
sudo certbot renew --dry-run
报错:Failed to renew certificate mydomain.cn with error: The manual plugin is not working; there may be problems with your existing configuration. The error was: PluginError(‘An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.’,)
错误提示表明你当前的证书是使用了 **manual**
** 插件** 申请的,而 certbot
在自动续期时需要一个验证钩子(--manual-auth-hook
)来完成身份验证。由于手动插件需要额外的配置来验证域名所有权,自动续期时无法进行交互,因此出现了错误。
为了解决这个问题,你有几个选择:
1. 切换到自动验证插件(推荐)
如果你之前使用的是 manual
插件,你可以将其切换为 DNS 插件 或 HTTP 插件,这两种方式支持自动化续期。
- HTTP 插件:通过在服务器上临时创建一个验证文件来完成验证。适用于你可以控制 HTTP 服务器的情况(如 Nginx 或 Apache)。
你可以运行以下命令来使用 HTTP 插件:
sudo certbot --nginx # 如果你使用 Nginx
sudo certbot --apache # 如果你使用 Apache
这样,certbot
会自动配置并验证域名。
- DNS 插件:如果你使用的是 DNS 记录验证(适用于你使用外部 DNS 服务商),可以使用
certbot-dns
插件来自动更新 DNS 记录。
如果你希望使用 DNS 插件,你可以安装相应的插件并配置它:
sudo apt install python3-certbot-dns-<dns_provider> # 根据你的 DNS 服务商选择插件
配置好后,可以运行如下命令进行验证和续期:
sudo certbot --dns-<dns_provider> --dns-<dns_provider>-credentials /path/to/credentials.ini -d yourdomain.com
2. 保留手动验证(不推荐,复杂)
如果你仍然希望使用手动验证(例如,如果你需要完全控制 DNS 记录),你可以通过 --manual-auth-hook
和 --manual-cleanup-hook
配置身份验证钩子脚本来自动化验证过程。
- 首先,需要编写验证钩子脚本来自动化 DNS 或文件验证过程。
- 然后在
certbot
命令中提供这些脚本,配置方式如下:
certbot renew --manual-auth-hook /path/to/auth-hook.sh --manual-cleanup-hook /path/to/cleanup-hook.sh
这种方式比较复杂,并且不如自动化插件方便。
3. 重新申请证书
如果证书已经过期且你无法解决 manual
插件的自动续期问题,最简单的方法是重新申请证书,并选择一个支持自动续期的插件。
可以通过如下命令申请证书:
sudo certbot --nginx -d mydomain.cn # 如果使用 Nginx
sudo certbot --apache -d mydomain.cn # 如果使用 Apache
在申请过程中,选择 HTTP 验证方式,这样证书可以自动续期,不需要手动干预。
总结:
如果你希望避免手动干预,建议切换到支持自动续期的插件(如 HTTP 或 DNS 插件)。如果你仍然希望使用手动插件,则需要编写并配置认证钩子脚本。这些方式会让你轻松处理证书续期问题。
报错:The requested nginx plugin does not appear to be installed
对于 CentOS 8 系统,你可以按照以下步骤安装 certbot
的 Nginx 插件并处理证书问题。
1. 安装 EPEL 仓库
首先,确保你的系统已经启用了 EPEL(Extra Packages for Enterprise Linux)仓库。因为 certbot-nginx
插件在 EPEL 仓库中:
sudo dnf install epel-release
2. 安装 Certbot 和 Nginx 插件
然后,安装 certbot
和 Nginx 插件:
sudo dnf install certbot python3-certbot-nginx
这个命令会安装 certbot
及其用于与 Nginx 配合工作的插件。
3. 检查 Nginx 配置
在继续之前,确认你的 Nginx 配置是正确的,可以通过以下命令测试配置:
sudo nginx -t
如果有任何错误,修复它们并重新加载 Nginx 配置:
sudo systemctl restart nginx
4. 使用 Certbot 申请证书
安装了插件后,使用 certbot
命令申请证书:
sudo certbot --nginx -d mydomain.cn
--nginx
参数会让 certbot
自动检测 Nginx 配置并为你申请证书。
5. 测试自动续期
安装并申请证书后,确认证书是否能够自动续期。可以通过以下命令测试:
sudo certbot renew --dry-run
这将模拟续期过程,确保一切配置正确。如果没有错误,表示续期会成功。
6. 自动续期
为了确保证书在到期时自动续期,你可以使用 certbot
自带的定时任务。如果系统没有自动设置,你可以手动设置一个定时任务来自动续期证书并重载 Nginx:
编辑 cron 任务:
sudo crontab -e
在文件中添加以下行,确保每天自动检查并续期证书:
0 0 * * * certbot renew --quiet && systemctl reload nginx
这会每天午夜时分检查证书是否即将过期,并在需要时进行续期,续期后重载 Nginx 使新证书生效。
方案一:编辑 /etc/crontab
/etc/crontab
比普通的 crontab 多一个 用户字段,格式如下:
c
复制编辑
# ┌───────────── 分钟(0 - 59)
# │ ┌─────────── 小时(0 - 23)
# │ │ ┌───────── 日(1 - 31)
# │ │ │ ┌─────── 月(1 - 12)
# │ │ │ │ ┌───── 星期(0 - 7)(0 和 7 都表示星期天)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * user command
🧾 示例 /etc/crontab
配置:
0 0 * * * root certbot renew --quiet && systemctl reload nginx
⛳ 解释: 每天 00:00 以 root 身份执行 certbot renew
和 reload nginx 的命令。
补充建议:
- 确保你的
certbot
与systemctl
命令可以在无交互的 shell 中运行; - 你可以在
/var/log/syslog
或/var/log/cron
查看任务执行记录(取决于系统); - 如需调试,先把
--quiet
去掉; nginx
必须是通过systemctl
管理的服务。
7. 手动证书申请(如果需要)
如果你在 certbot
自动申请过程中遇到问题,也可以选择手动申请证书,方法是:
sudo certbot certonly --nginx -d mydomain.cn
然后手动将证书路径配置到 Nginx 配置文件中:
server {
listen 443 ssl;
server_name mydomain.cn;
ssl_certificate /etc/letsencrypt/live/mydomain.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.cn/privkey.pem;
# 其他配置...
}
修改完后,重新加载 Nginx 配置:
sudo systemctl reload nginx
总结
按照以上步骤,你应该能在 CentOS 8 系统上成功安装 certbot
和 Nginx 插件,申请和续期 Let’s Encrypt 证书。
报错:no valid A records found for mydomain.cn; no valid AAAA records found for MyDomain.cn
例如在阿里云购买的域名,需要在阿里云域名管理控制台中配置DNS解析的A记录,排查后发现仅配置了www.mydomain.cn,没有配置mydomain.cn导致的该报错
出现两个域名配置
查看域名证书配置:sudo certbot certificates 返回两个证书配置如下
mydomain.cn
mydomain.cn-001
通常是因为domain配置不同观察返回的数据中的Domains,例如:
一个为:Domains: mydomain.cn
一个为:Domains: mydomain.cn www.mydomain.cn
如何解决?
- 删除过期证书: 如果你不再需要
mydomain.cn
的旧证书(已经过期的证书),可以手动删除它,保持当前有效的证书。执行以下命令来删除过期的证书:
sudo certbot delete --cert-name mydomain.cn
这将删除过期的证书,保留有效的证书。
- 检查证书链和配置: 确保 Nginx 或你的 Web 服务器使用的是正确的证书路径。如果你的 Nginx 配置仍然指向旧证书路径(如
/etc/letsencrypt/live/mydomain.cn/fullchain.pem
),需要更新为新证书路径。
打开 Nginx 配置文件,检查以下部分:
ssl_certificate /etc/letsencrypt/live/mydomain.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.cn/privkey.pem;
如果你使用的是 mydomain.cn-0001
证书,需要将其路径更新为:
ssl_certificate /etc/letsencrypt/live/mydomain.cn-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.cn-0001/privkey.pem;
- 重新加载 Nginx 配置: 更新 Nginx 配置后,重新加载配置以使其生效:
sudo systemctl reload nginx
- 配置自动续期: 确保证书的自动续期正常工作。你可以通过运行以下命令来测试自动续期功能:
sudo certbot renew --dry-run
这将模拟自动续期过程,确保续期操作不会出现问题。
总结
- 删除不再需要的旧证书,保留有效证书。
- 更新 Nginx 配置,确保使用正确的证书路径。
- 测试自动续期功能,确保续期配置无误。
注意
- 更新证书后需要刷新Springboot的p12文件并重启服务
- nginx serverName配置要包含实际访问的地址,例如:mydomain.cn,www.mydomain.cn