file_get_contents():找不到证书CN



我们有两个域(均为https):一个作为主域https://dev.project.com/另一个用于图像https://dev-images.project.com/.首页加载图像很好,但我在file_get_contents上遇到了这个问题。

ErrorException in Collection.php line 228:
file_get_contents(): Unable to locate certificate CN
in Collection.php line 228
at HandleExceptions->handleError('2', 'file_get_contents(): Unable to locate certificate CN', '')
at file_get_contents('https://dev-images.project.com/images/12012_resized.jpg') in Collection.php line 228

文件本身存在,并在浏览器中签入时打开。我检查了这个解决方案,但所有测试都是阳性的:

openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array (size=12) ...

php.ini

extension=php_openssl.dll
allow_url_fopen = On

证书是本地生成的,并在php.ini 中设置

curl.cainfo = "D:wamp64cacert.pem"

我的开发站在Window10上有wamp64服务器,Php 5.6。网站基于Laravel5。

试着像这样将路径传递到您的cafile。

$opts=array(
    "ssl"=>array(
        "cafile" => "D:\wamp64\cacert.pem",
        "verify_peer"=> true,
        "verify_peer_name"=> true
    )
);
file_get_contents($url,false,stream_context_create($opts));

edit:如果此操作仅在本地服务器中失败,请检查您是否已在本地服务器的cacert.pem中添加了本地创建的SSL证书,并且该证书中没有错误或多余的行。

最新更新