修复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


参考资料:


更多文章
  • SEO学习笔记
  • 密码技术简明教程(一):对称加密和非对称加密
  • Kubernetes 笔记
  • go mod 和 logrus 路径大小写的问题
  • Flask自动加载Blueprint
  • 在KVM里安装Minikube
  • 搞定面试中的系统设计题
  • Crontab + Sendmail实现定时任务并且通知
  • Nginx设置Referer来防止盗图
  • Graphviz dot简明教程
  • jQuery简明教程
  • Python RQ(Redis Queue)添加gevent支持
  • 读《超级运营术》- 如何做社区?
  • 技术人,光有技术是不行的
  • 使用shairport-sync搭建airplay音频服务器