SSL:错误:0B080074:x509证书例程:X509_CHECK_PRIVATE_KEY:密钥值不匹配

dsekswqp  于 2022-09-20  发布在  Nginx
关注(0)|答案(17)|浏览(1153)

我无法设置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,指令指向正确的私钥和证书。

我还检查了模数,我得到了密钥和证书的不同模数。

谢谢你的帮助。:)

jobtbby3

jobtbby316#

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

之前(这是错误的):

cat ca_bundle.crt certificate.crt > bundle_chained.crt

之后(这是正确的)

cat certificate.crt ca_bundle.crt > bundle_chained.crt

请不要忘记更新适当的配置文件(现在SSLCERTIFICATE必须指向链接的CRT)为

server {
    listen              443 ssl;
    server_name         www.example.com;
    ssl_certificate     bundle_chained.crt;
    ssl_certificate_key www.example.com.key;
    ...
}

nginx manpage

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

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

ibps3vxo17#

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

openssl x509 -noout -modulus -in certificate.crt | openssl md5
openssl rsa -noout -modulus -in privateKey.key | openssl md5

相关问题