GNU Wget (GnuTLS build); the alias is the OpenSSL build's wordingcurl
错误信息
The certificate's owner does not match hostname 'api.example.com'
也可能输出为
- ERROR: no certificate subject alternative name matches
使用 GnuTLS 构建的 wget 打印这一行;使用 OpenSSL 构建的版本则打印“ERROR: no certificate subject alternative name matches”,下一行接着是“requested host name '<host>'.”。其中的主机就是你 URL 中的主机。
含义
证书通过了验证,但它是为 URL 中主机以外的其他名称签发的,因此 wget 停止运行。主机会与证书的主题备用名称扩展中的 DNS 名称比较,如今所有 CA 都把证书覆盖的名称放在这个扩展里。wget 以退出状态 5 退出。
原因
证书没有覆盖这个名称
常见为 www.example.com 签发的证书不覆盖 example.com、api.example.com 或新的子域名;每个名称都必须列出,而通配符只覆盖一级标签。
URL 中使用的是 IP 地址或内部别名
常见从 https://10.0.0.5/ 或容器、主机别名下载时,能够连到服务器,但请求的名称不在证书列出的名称之中。
服务器发送了另一个网站的证书
偶见在共享主机和 Ingress 控制器上,没有独立 server 块的名称会得到默认证书。
修复方法
- 1.
列出证书覆盖的名称
将 subjectAltName 条目与 URL 中的主机对比。
bash echo | openssl s_client -connect api.example.com:443 -servername api.example.com 2>/dev/null \ | openssl x509 -noout -ext subjectAltName - 2.
重新签发证书,补上缺失的名称
把客户端使用的每个主机名都加入证书请求,然后部署并重新加载。
bash sudo certbot certonly --nginx -d example.com -d www.example.com -d api.example.com - 3.
使用证书中列出的名称
如果服务器可以通过某个已列出的名称访问,就在 URL 中使用该名称,而不是 IP 地址或别名。
bash # Download through a name the certificate lists, not an IP or alias wget https://www.example.com/file.tar.gz
相关错误
curl: (60) SSL: no alternative certificate subject name matches target hostname…curl (OpenSSL backend)fatal: unable to access 'https://git.example.com/team/app.git/': SSL: certifica…git over HTTPS with libcurl-gnutls (Debian, Ubuntu)x509: certificate is valid for example.com, not api.example.comGo crypto/x509