前几天在测试环境部署的服务几天突然报错:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
查看相关代码是httpclient调用https://xx.com接口报错了,从报错信息查看应该是证书问题。

curl https://xx.com -v

image.png
查看证书相关信息,发现已经过期了,而且证书的域名不一致
直接浏览器打开这个网址,点击查看域名证书
image.png
发现和curl 返回的证书域名,过期时间都不一样
尝试本地更新证书:

update-ca-trust

后者是不是本地时间有问题,尝试更新服务器时间

ntpdate pool.ntp.org

再次查看curl https://xx.com -v
返回的证书和之前一样,这就奇怪了。

vi /etc/hosts

发现有同事修改了hosts文件,把这个域名转发到了其他服务上去了,导致了本地证书和远程证书不一致的问题。
注释了这行host配置,服务恢复正常~