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


参考资料:


更多文章
  • 预防缓存击穿
  • flutter开发体验汇报
  • 自己封装一个好用的Dart HTTP库
  • Flutter应用启动后检查更新
  • Grafana Gravatar头像显示bug修复
  • flutter中使用RESTful接口
  • Vim YouCompleteMe使用LSP(以dart为例)
  • flutter webview加载时显示进度
  • SQLAlchemy快速更新或插入对象
  • 修复Linux下curl等无法使用letsencrypt证书
  • 欣赏一下K&R两位大神的代码
  • MySQL的ON DUPLICATE KEY UPDATE语句
  • 使用microk8s快速搭建k8s
  • Python中优雅的处理文件路径
  • Go语言MySQL时区问题