我已获得以下文件,用于为在域 example.com
上运行的网站设置 TLS :
example.com.key
(包含私钥)example.com.cer
(含一张证书)intermediate_example.com.crt
(含两张证书)example.com.csr
(包含一个证书请求)我正在使用 Traefik 来托管站点,并且我在
dynamic.yml
中已经像这样配置了 Traefik配置: tls:
certificates:
- certFile: "certs/example.com.cer"
keyFile: "certs/example.com.key"
stores:
- default
这样做导致我可以通过 Chrome 和 Firefox 访问一个网站,但无论何时尝试使用 curl
的请求(或任何使用其库的程序),我收到以下错误:➜ ~ curl -v https://test.example.com/
* Trying xxx.xxx.xxx.xxx:443...
* Connected to test.example.com (xxx.xxx.xxx.xxx) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html
为什么这在浏览器中有效,而不是通过 curl
?我已确保
ca-certificates
软件包已安装在主机上,即使我下载了most recent CA bundle并使用 curl --cacert cacert.pem …
, 这没用。我在这里想念什么?
最佳答案
它不起作用的原因是 Traefik 发送给客户端的内容中缺少中间证书。
浏览器可以使用权威信息访问机制来解决这个问题,甚至 macOS 也会这样做,从带外获取丢失的信息,从而允许您正常访问该站点。一些背景是given here .
这显然是服务器上的配置错误。要修复它,至少对于 Traefik,您可以将所有内容连接到一个 .pem
文件。您无需在此处添加 CSR 文件:
cat example.com.key example.com.cer intermediate_example.com.crt > cert.pem
然后,在 Traefik 的配置中指定相同的文件两次:tls:
certificates:
- certFile: "certs/cert.pem"
keyFile: "certs/cert.pem"
stores:
- default
this discussion 中也提到了这一点在 Traefik 社区委员会。
关于ssl - Traefik TLS 证书导致 curl 出现 "unknown CA"错误,适用于浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72444372/