首页 > 解决方案 > PHP curl:(60)SSL证书问题:自签名证书

问题描述

当 PHP 发出 HTTP 发布请求时,会显示一条错误消息。这是我的错误信息:

ttg@pro1-nginx:~$ curl  https://10.10.10.20:9997/playwpt/admin
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
ttg@pro1-nginx:~$ 

在测试环境中,使用 nginx 作为 Web 服务。PHP 处理动态请求。在服务器中,我想测试 PHP 发布请求。使用curl命令访问时显示SSL证书有问题

我测试了一个解决方案:

从curl官网下载根证书:cacert.pem,然后修改php.ini添加证书并重启web服务。

将以下内容添加到 php.ini

[SSL]
curl.cainfo = "/etc/php/7.2/cacert.pem"
openssl.cafile = "${curl.cainfo}"

以上方法配置好后,当我在curl命令后面加上“-k”参数时,就可以访问了,但是如果不加这个参数,还是会报上面一样的错误。

这是我的nginx配置:

server{
   listen       80;
   server_name  10.10.10.40;
   index index.html index.htm index.php;
   root  /usr/share/nginx/html;                            
   location ~ .*\.(php|php5)?${      
         fastcgi_pass  unix:/run/php/php7.2-fpm.sock;
         #fastcgi_pass  127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
         }

    location ~ .(version.xml|version.fuh|version.fuh.xxx|Boot.swf)${
         expires      3m;
         }

    location ~ .* 
    (gif|jpg|jpeg|png|bmp|dat|zip|jz|mp3|exe|dds|alpha|rar|spr|dll|pdb|pak|xxx|pck|cur)${
         expires      240h;
         }

    location ~ .*\.(js|css|txt|xml|lua|htm|html|cfg|ini|hlsl|fuh|swf|cab)?${
         expires      120m;
         }
    }

我想要的效果是即使curl命令后面不加“-k”参数也能访问。我怎么解决这个问题?

请帮帮我,谢谢!

标签: phpsslcurl

解决方案


推荐阅读