关于php:CURL请求在SSL上失败?

Curl request is failing on the SSL?

我有这个代码

1
2
3
4
5
6
7
    if(ereg("^(https)",$url))
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
    // execute, and log the result to curl_put.log
    $result = curl_exec($curl);


    $error = curl_error($curl);

指定的错误是

1
SSL read: error:00000000:lib(0):func(0):reason(0), errno 104

关于原因的任何想法


使用第三方库时遇到类似的隐秘错误。我尝试了CURLOPT_SSL_VERIFY[PEER|HOST],但没有什么区别。我的错误消息是类似的:

1
SSL read: error:00000000:lib(0):func(0):reason(0), errno 54

因此,我访问了http://curl.haxx.se/libcurl/c/libcurl-errors.html,查找错误代码54。

1
CURLE_SSL_ENGINE_SETFAILED (54) Failed setting the selected SSL crypto engine as default!

但是,这是错误的-我在应用程序的其他部分使用curl发出了其他HTTPS请求。因此,我一直在挖掘,发现了这个问题,R&RCurl:libcurl中的错误54,其中包含以下宝石:

The output you see is from lib/ssluse.c in libcurl's source code and the"errno" mentioned there is not the libcurl error code but the actual errno variable at that time.

因此,不要让curl_error()的输出误导您。而是使用curl_errno()获取正确的错误代码,在这种情况下,该错误代码实际上为56,CURLE_RECV_ERROR。主机名错误...


使用SSL时,请确保已从php.ini中打开了openssl扩展名。


我遇到了同样的问题。原来,目标系统上的SSL配置错误。

在检查了php curl模块,GuzzleHttp版本,openssl版本之后,我在浏览器中调用了链接,该链接正常了。但是,在控制台上使用curl --tlsv1 -kv https://www.example.com仍然存在错误。

因此,我在https://www.ssllabs.com/ssltest/上检查了ssl配置,它的等级为B。在此之前,我从未见过一些在线证书状态协议(OCSP)错误。最后,我将目标系统上的配置更改为https://cipherli.st/上的建议,重新启动了Web服务器,一切正常。 ssllabs的新评级现在为A +。

我的Nginx配置(Ubuntu 14.04,Nginx 1.4.6-1ubuntu3.5):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ssl     on;
ssl_certificate /etc/ssl/certs/1_www.example.com_bundle.crt;
ssl_certificate_key     /etc/ssl/private/www.example.com.key;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers"EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
ssl_session_cache shared:SSL:10m;
#ssl_session_tickets off; # Requires nginx >= 1.5.9
ssl_stapling on; # Requires nginx >= 1.3.7
ssl_stapling_verify off; # Requires nginx => 1.3.7
ssl_dhparam /etc/ssl/private/dhparams.pem;
ssl_trusted_certificate /etc/ssl/startssl.ca.pem;
resolver 8.8.8.8 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security"max-age=63072000; www.example.com; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;


我在函数curl_error上打印了相同的错误,但这不一定与SSL有关。最好使用功能curl_errno打印准确的错误编号,然后从那里可以更好地进行诊断。就我而言,它向我返回了52个错误代码,我可以从那里进行调试,实际上另一台服务器未发送任何数据。


添加:

curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 0);

我有同样的错误,对我来说很好。


我认为您的意思是使用CURLOPT_SSL_VERIFYHOST,而不是CURLOPT_SSL_VERIFYPEER