gpt4 book ai didi

php - SSL 例程 :tls_process_server_certificate:certificate verify failed

转载 作者:行者123 更新时间:2023-12-04 22:34:46 26 4
gpt4 key购买 nike

从昨晚开始,我的几个脚本(在不同的服务器上)使用 file_get_contents("https://...")curl功能停止工作。
失败的示例请求:

file_get_contents("https://domain.tld/script.php");

错误 :
PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /home/domain/public_html/script.php on line 19
我已经使用以下方法“修复”了问题:
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);

file_get_contents("https://domain.tld/path/script.php", false, stream_context_create($arrContextOptions));
“修复”远非理想,因为我没有验证连接的真实性,但在我了解问题的根源以及如何防止它再次发生之前,我将被迫使用它。

备注 :
  • 带有 Curl 的 PHP 脚本也停止工作,修复方法类似:curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); ;
  • SSL证书由 Let's Encrypt 颁发并且昨晚更新了(“2020/12/24之前无效”);
  • 所有服务器具有相同的时区;
  • 我正在使用 CentOS 7/Ubuntu 18Virtualmin ;
  • 如果我打开 "https://domain.tld/script.php"在 Firefox/Chrome 上,不显示 SSL 警告并且证书有效;
  • 我尝试更新 CA 证书( yum install ca-certificates.noarch ),但已安装最新版本;

  • 我明白出了什么问题,我无法弄清楚它为什么开始发生以及如何修复它(真正的修复)。

    问题 :
    如何修复并防止它再次发生?

    最佳答案

    问题是 CA 证书过时,我在 Let's Encrypt community thread 上找到了解决方案:
    手动解决方案:

  • 替换/home/[domain]/ssl.ca的内容与 lets-encrypt-r3-cross-signed.pem
  • 重启 apache/nginx

  • 虚拟机解决方案:
  • 转至 Virtualmin -> Server Configuration -> SSL Certificate -> CA Certificate
  • 选项一:选择upload file并使用 lets-encrypt-r3-cross-signed.pem
  • 选项 2:粘贴 lets-encrypt-r3-cross-signed.pem 的内容使用 Pasted certificate text选项。

  • 按“Save Certificate

  • enter image description here

    笔记:
    这个问题是 fixed on webmin 1.970 ,所以请确保您安装了最新版本,这不是我的情况,因为 webmin repo未启用。如果这也是您的情况,只需启用或添加 webmin 存储库并运行 yum update .

    关于php - SSL 例程 :tls_process_server_certificate:certificate verify failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65442972/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com