使用中间密钥在 nginx 上安装 SSL 证书时出现问题

har*_*ryg 12 ssl nginx

我正在尝试在我的 Ubuntu 服务器上安装 SSL 证书。我已经从我的 CA 购买了证书并下载了证书本身和中间证书。如此:

我的证书: mydomain.crt
中级证书: GandiStandardSSLCA.pem

我也有(使用 openssl 制作)

我的私钥 (?): mydomain.key
和签名请求: mydomain.csr

我已将所有这些文件上传到我的服务器,并按照指南将我的证书与中间证书结合起来:

cat mydomain.crt GandiStandardSSLCA.pem > mydomain-bundle.crt
Run Code Online (Sandbox Code Playgroud)

然后我将以下内容添加到我的虚拟主机的配置中:

listen   443 ssl;
ssl_certificate       /etc/nginx/ssl/mydomain-bundle.crt;
ssl_certificate_key   /etc/nginx/ssl/mydomain.key;
Run Code Online (Sandbox Code Playgroud)

但是当我重新启动 nginx 时,出现此错误:

* 重启 nginx
* 停止 nginx nginx [OK]
nginx: [emerg] SSL_CTX_use_PrivateKey_file("/etc/nginx/ssl/mydomain.key") failed (SSL: error:0B080074:x509 certificateroutines:X509_check_private_key:key values mismatch)配置文件 /etc/nginx/nginx.conf 测试失败

任何想法为什么以及如何解决?

dav*_*vey 21

您的密钥列表是否正常:

openssl rsa -in /etc/nginx/ssl/mydomain.key
Run Code Online (Sandbox Code Playgroud)

密钥和证书的模数是否匹配:

openssl x509  -in mydomain.crt -modulus 

openssl rsa  -in qa.server.key  -modulus
Run Code Online (Sandbox Code Playgroud)

这些数字必须匹配。