修复Linux下curl等无法使用letsencrypt证书

遇到一个奇怪的问题,由于我的博客使用的是letsencrypt,浏览器可以正常访问,但是命令行却不可以。

$ curl https://git.jiajunhuang.com
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

除了curl,git和wget等也不可以用,这就很奇怪了,为什么浏览器可以但是命令行却不可以呢?

原因是Nginx配置中,ssl_certificate 我之前指向的是生成的中间的 crt 文件而不是最后的 chained certificate。 Nginx官方文档给出的方案是:

不过我们不必这么做,此处仅作阅读

$ cat www.example.com.crt bundle.crt > www.example.com.chained.crt

我们不必这么做,因为无论是 certbot 还是 acme.sh 都会帮我们处理好。把 ssl_certificate 的路径改成证书所在路径, 名称改为 fullchain.crt 即可。

例如:

ssl_certificate /etc/acme.sh/jiajunhuang.com/fullchain.cer;

这下大功告成:

$ curl -I https://jiajunhuang.com
HTTP/2 302 
server: nginx/1.14.2
date: Tue, 26 Nov 2019 15:07:03 GMT
content-type: text/html; charset=utf-8
location: /404


参考资料:


更多文章
  • 折腾Kubernetes
  • 协程(coroutine)简介 - 什么是协程?
  • goroutine 切换的时候发生了什么?
  • Prometheus 数据类型
  • Gin源码阅读与分析
  • 如何面试-作为面试官得到的经验
  • 自己写一个容器
  • Golang(Go语言)中实现典型的fork调用
  • 软件开发之禅---大事化小,各个击破
  • 程序员的自我修养:链接,装载与库 阅读笔记
  • Redis源码阅读与分析二:双链表
  • Redis源码阅读与分析三:哈希表
  • Redis源码阅读与分析一:sds
  • Golang runtime 源码阅读与分析
  • Golang的一些坑