Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SSL:错误:0B080074:x509证书例程:x509\u检查\u私钥:密钥值不匹配_Ssl_Nginx_Openssl_Certificate_Key - Fatal编程技术网

SSL:错误:0B080074:x509证书例程:x509\u检查\u私钥:密钥值不匹配

SSL:错误:0B080074:x509证书例程:x509\u检查\u私钥:密钥值不匹配,ssl,nginx,openssl,certificate,key,Ssl,Nginx,Openssl,Certificate,Key,我无法设置SSL。我在谷歌上搜索了一下,找到了一些解决方案,但没有一个对我有效。我需要一些帮助,请 以下是我尝试重新启动nginx时遇到的错误: root@s17925268:~# service nginx restart Restarting nginx: nginx: [emerg] SSL_CTX_use_PrivateKey_file("/etc/nginx/conf.d/ssl/ssl.key") failed (SSL: error:0B080074:x509 certificat

我无法设置SSL。我在谷歌上搜索了一下,找到了一些解决方案,但没有一个对我有效。我需要一些帮助,请

以下是我尝试重新启动nginx时遇到的错误:

root@s17925268:~# service nginx restart
Restarting nginx: nginx: [emerg] SSL_CTX_use_PrivateKey_file("/etc/nginx/conf.d/ssl/ssl.key") failed (SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch)
nginx: configuration file /etc/nginx/nginx.conf test failed
我的证书来自StartSSL,有效期为1年

以下是我测试的内容:

  • 证书和私钥没有尾随空格
  • 我没有使用默认的server.key文件
  • 我检查了nginx.conf和 指令指向正确的私钥和证书
我还检查了模数,得到了密钥和证书的不同模数

谢谢你的帮助。:)

  • 确保您的证书和密钥为PEM格式。如果没有,则使用openssl命令转换它们
  • 检查公钥的MD5散列,以确保它与私钥中的内容匹配

    openssl x509 -noout -modulus -in certificate.crt | openssl md5
    openssl rsa -noout -modulus -in privateKey.key | openssl md5
    
  • 我得到了一个MD5哈希,密钥和证书的结果都不同

    这说明了一切。您的密钥和证书不匹配


    模量应匹配。确保您有正确的密钥。

    一旦确定它们不匹配,您仍然有一个问题--如何处理它。通常,证书可能只是组装不正确。当CA为您的证书签名时,他们会向您发送一个类似的块

    -----BEGIN CERTIFICATE-----
    MIIAA-and-a-buncha-nonsense-that-is-your-certificate
    -and-a-buncha-nonsense-that-is-your-certificate-and-
    a-buncha-nonsense-that-is-your-certificate-and-a-bun
    cha-nonsense-that-is-your-certificate-and-a-buncha-n
    onsense-that-is-your-certificate-AA+
    -----END CERTIFICATE-----
    
    -----BEGIN CERTIFICATE-----
    MIICC-this-is-the-certificate-that-signed-your-request
    -this-is-the-certificate-that-signed-your-request-this
    -is-the-certificate-that-signed-your-request-this-is-t
    he-certificate-that-signed-your-request-this-is-the-ce
    rtificate-that-signed-your-request-A
    -----END CERTIFICATE-----
    -----BEGIN CERTIFICATE-----
    MIICC-this-is-the-certificate-that-signed-for-that-one
    -this-is-the-certificate-that-signed-for-that-one-this
    -is-the-certificate-that-signed-for-that-one-this-is-t
    he-certificate-that-signed-for-that-one-this-is-the-ce
    rtificate-that-signed-for-that-one-this-is-the-certifi
    cate-that-signed-for-that-one-AA
    -----END CERTIFICATE-----
    
    他们还将向您发送一个捆绑包(通常是两个证书),表示他们授予您证书的权限。这看起来像

    -----BEGIN CERTIFICATE-----
    MIIAA-and-a-buncha-nonsense-that-is-your-certificate
    -and-a-buncha-nonsense-that-is-your-certificate-and-
    a-buncha-nonsense-that-is-your-certificate-and-a-bun
    cha-nonsense-that-is-your-certificate-and-a-buncha-n
    onsense-that-is-your-certificate-AA+
    -----END CERTIFICATE-----
    
    -----BEGIN CERTIFICATE-----
    MIICC-this-is-the-certificate-that-signed-your-request
    -this-is-the-certificate-that-signed-your-request-this
    -is-the-certificate-that-signed-your-request-this-is-t
    he-certificate-that-signed-your-request-this-is-the-ce
    rtificate-that-signed-your-request-A
    -----END CERTIFICATE-----
    -----BEGIN CERTIFICATE-----
    MIICC-this-is-the-certificate-that-signed-for-that-one
    -this-is-the-certificate-that-signed-for-that-one-this
    -is-the-certificate-that-signed-for-that-one-this-is-t
    he-certificate-that-signed-for-that-one-this-is-the-ce
    rtificate-that-signed-for-that-one-this-is-the-certifi
    cate-that-signed-for-that-one-AA
    -----END CERTIFICATE-----
    
    但不幸的是,它们的标签不会这么清晰

    因此,一种常见的做法是将这些文件打包到一个文件中——您的证书,然后是签名证书。但由于它们不容易区分,有时会有人不经意间把它们放在另一个顺序——签署证书,然后是最终证书——而没有注意到。在这种情况下,您的证书将与您的密钥不匹配

    您可以通过运行

    openssl x509 -noout -text -in yourcert.cert
    
    在顶部附近,您应该看到“主题:”以及类似于您的数据的内容。如果它看起来像您的CA,那么您的包可能顺序错误;您可以尝试进行备份,然后将最后一个证书移到开头,希望它就是您的证书


    如果这不起作用,您可能需要重新颁发证书。当我创建CSR时,我喜欢清楚地标记它用于哪个服务器(而不仅仅是ssl.key或server.key),并在名称中创建一个带有日期的副本,如mydomain.20150306.key等。这样,它们的私钥和公钥对就不太可能与另一组混淆

    如果发生这种情况,并且您正在使用Let's Encrypt/certbot,原因很可能是您使用了
    chain.pem
    而不是
    fullchain.pem

    应该是这样的:

    ssl_certificate /etc/certbot/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/certbot/live/example.com/privkey.pem;
    

    请参见

    在本例中,我想更改SSL证书,因为我已更改了服务器,因此必须使用以下命令创建新的CSR:

     openssl req -new -newkey rsa:2048 -nodes -keyout mysite.key -out mysite.csr
    
    我已将mysite.csr文件发送给公司SSL提供商,在收到证书crt后,我重新启动了nginx,我收到了这个错误

     (SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch)
    
    经过大量调查,错误在于键文件中的模块与crt文件中的模块不一样

    因此,为了使其工作,我创建了一个新的csr文件,但我必须使用此命令更改文件名

     openssl req -new -newkey rsa:2048 -nodes -keyout mysite_new.key -out mysite_new.csr
    

    然后,我从该公司的提供商那里收到了一个新的crt文件,重新启动nginx,它就工作了

    我在这个问题上的5美分:

    我也有同样的问题。经过大约一个小时的检查,我发现我粘贴的证书不正确


    如果您有这样的错误,请检查您的证书。我也遇到了同样的问题,最后通过更改证书文件中pem块的顺序解决了这个问题

    证书块应该放在文件的开头,然后是中间块,然后是根块

    我通过将有问题的证书文件与工作证书文件进行比较来意识到这个问题。

    当您的CA颁发中间证书时,也会发生这种情况 我在使用nginx时遇到了这个问题(两次),本文中的任何解决方案都没有解释这个问题。一位名叫马可的绅士在这里写的博文把它钉死了,我把它贴在这里是为了任何一个遇到我看到的东西的人

    在我的例子中,go daddy是CA,这是特定于他们如何发布证书和中间证书包的

    这是马可博客文章的摘录 使用Nginx,如果您的CA包含一个中间证书,则必须创建一个包含您的证书和CA的中间证书的单链证书文件

    您可以使用此命令创建名为example.com.chained.crt的组合文件:

    cat example.com.crt intermediate.crt>example.com.chained.crt

    对于Nginx:

  • openssl-req-newkey rsa:2048-nodes-keyout-domain.com.key-out-domain.com.csr

  • SSL文件
    domain\u com.crt
    domain\u com.ca绑定
    文件,然后在粘贴
    domain.com.chained.crt
    中复制新文件

  • 3:添加nginx文件:

  • ssl\u证书/home/user/domain\u ssl/domain.com.chained.crt
  • ssl\u证书\u密钥/home/user/domain\u ssl/domain.com.key

  • 延迟重新启动Nginx。

    我遇到了这个问题,因为我以错误的顺序添加了捆绑包和证书,所以这可能会帮助其他人

    之前(哪一个是错误的):

    之后(哪个是对的)

    请不要忘记更新相应的conf(ssl_证书现在必须指向链接的crt),如下所示

    从:

    如果服务器证书和捆绑包的连接顺序错误, nginx将无法启动并显示错误消息:

    SSL_CTX_use_PrivateKey_file(" ... /www.example.com.key") failed
       (SSL: error:0B080074:x509 certificate routines:
        X509_check_private_key:key values mismatch)
    

    在我的情况下,问题是我信任sertific
    SSL_CTX_use_PrivateKey_file(" ... /www.example.com.key") failed
       (SSL: error:0B080074:x509 certificate routines:
        X509_check_private_key:key values mismatch)
    
     sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
    
    cat myDomain.crt EntityCertCA.crt TrustedRoot.crt > bundle.crt
    
     ssl_certificate "/etc/pki/nginx/bundle.crt";
    
    systemctl restart nginx.service
    
    ssl_certificate /path/to/cert.crt;
    ssl_certificate_key /path/to/key.key;