PHP Curl连接拒绝Localhost自签名证书

时间:2019-03-05 22:44:48

标签: php ssl curl self-signed-certificate

我在本地主机上有两个本地服务器(配置为nginx代理后面的docker容器),我想在服务器A中使用CURL来使用服务器B的API。它们都使用带有自签名证书的SSL (也已配置)。

    curl_setopt($request, CURLOPT_CAINFO, __DIR__ . '/../' . getenv('SERVER_B_CA_CERT'));
    curl_setopt($request, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
    curl_setopt($request, CURLOPT_SSL_VERIFYPEER, getenv('CURL_SSL_VERIFYPEER'));
    curl_setopt($request, CURLOPT_SSL_VERIFYHOST, getenv('CURL_SSL_VERIFYHOST'));

CURLOPT_SSL_VERIFYHOST和CURLOPT_SSL_VERIFYPEER都设置为false。

我从PHP的curl库收到“连接被拒绝”(curl错误代码7)消息。我的容器之间没有防火墙,并且我的nginx代理似乎配置正确。服务器已经启动并正在监听,因为我已经能够使用Web浏览器和curl客户端连接到服务器。

有什么想法吗?

编辑:

php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "*   Trying 127.0.0.1..."
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* TCP_NODELAY set"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* connect to 127.0.0.1 port 443 failed: Connection refused"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "*   Trying ::1..."
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* TCP_NODELAY set"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* Immediate connect fail for ::1: Cannot assign requested address"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "*   Trying ::1..."
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* TCP_NODELAY set"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* Immediate connect fail for ::1: Cannot assign requested address"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* Failed to connect to server-b.local.com port 443: Connection refused"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "* Closing connection 0"
php_1       | [05-Mar-2019 22:49:40] WARNING: [pool www] child 66 said into stderr: "NOTICE: PHP message: CURL ERROR = Failed to connect to server-b.local.com port 443: Connection refused, CODE = 7"

0 个答案:

没有答案