记一次php函数问题

星空下的祈愿 1,173 0 状态:已收录

前两天刚好在测试php代码,发现curl和file_get_contents无法抓取https链接的内容

显示错误如下:

curl

curl: (60) Peer's Certificate issuer is not recognized

file_get_contents

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /www/wwwroot/test/index.php on line 8

Warning: file_get_contents(): Failed to enable crypto in /www/wwwroot/test/index.php on line 8

Warning: file_get_contents(https://127.0.0.1/index.php?type=test&key=123): failed to open stream: operation failed in /www/wwwroot/test/index.php on line 8

第一时间想到的就是百度一下,发现有替换CA证书、忽略验证、升级curl等方法,全部试下来似乎都没有用[aru_38].
正当我快要崩溃之时[aru_34],翻到了一篇外国大神的文章,拿谷歌翻译了一下,试了一下果然有用,现在给大家分享一下。

此方法仅适用于centos系统

1.下载网址所对应的2级证书(倒数第二级)

记一次php函数问题记一次php函数问题记一次php函数问题记一次php函数问题
2.导出证书并保存到桌面

记一次php函数问题 记一次php函数问题 记一次php函数问题 记一次php函数问题 记一次php函数问题 记一次php函数问题 记一次php函数问题
3.上传证书至服务器,并复制到/etc/pki/tls/certs/下
记一次php函数问题
4.登陆SSH,转换证书格式并将ca证书导入到linux证书库
命令如下(证书名称改成自己的):

记一次php函数问题
记一次php函数问题

openssl x509 -inform der -in /etc/pki/tls/certs/qiqiblog.cer -out /etc/pki/tls/certs/qiqiblog.pem
cat /etc/pki/tls/certs/qiqiblog.pem >> /etc/pki/tls/certs/ca-bundle.crt

5.重启nginx和php,问题解决!

发表评论 取消回复
表情 图片 链接 代码

分享