nginx
php
zf2
访问https时的问题
没有访问https时的代码
use Zend\Http\Client;
$httpClient = new Client();
$httpClient->resetParameters();
$httpClient->setEncType(Client::ENC_URLENCODED);
$httpClient->setUri($url);
$httpClient->setMethod(Request::METHOD_GET);
$response = $httpClient->send();
访问https时就会提示错误:Unable to enable crypto on TCP connection domainname make sure the sslcafile or sslcapath option are properly set for the environment.
增加以下代码即可
$httpClient->setAdapter("Zend\Http\Client\Adapter\Curl");
$options = array('http_client_options' => array(
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => array(
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_CAINFO => '/etc/nginx/conf.d/server.crt',
),
),);
$httpClient->setOptions($options);
因为采用了自己搭建的CA服务器,自己颁发的证书,此时系统可能会提示Error in cURL request: SSL certificate problem: self signed certificate
只要在文件/etc/php5/fpm/conf.d/20-curl.ini中增加已经生成的crt文件即可
curl.cainfo = /etc/nginx/conf.d/server.crt
service php-fpm restart