nginx无法加载ssl certifacate

我必须为一个网站添加ssl(https),我被给了一个SSL.CSR和一个SSL.KEY文件。 我dos2unix'ed他们(因为他们已经尾随^ M),并将其复制到服务器(CSR – > mywebsite.crt,密钥 – > mywebsite.key)。 我对nginx.conf做了如下修改:

@@ -60,8 +60,13 @@ } server { - listen 80; + listen 443; server_name ...; + ssl on; + ssl_certificate mywebsite.crt; + ssl_certificate_key mywebsite.key; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; # Set the max size for file uploads to 500Mb client_max_body_size 500M; 

重新启动nginx时发生错误:

 nginx: [emerg] PEM_read_bio_X509_AUX("/etc/nginx/mywebsite.crt") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE) 

我想这是因为mywebsite.crt文件的第一行包含'REQUEST',所以我从第一行和最后一行中删除'REQUEST',并重新启动nginx,并且遇到另一个错误:

 nginx: [emerg] PEM_read_bio_X509_AUX("/etc/nginx/mywebsite.crt") failed (SSL: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=algorithm, Type=X509_ALGOR error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=signature, Type=X509_CINF error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=cert_info, Type=X509 error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib) 

任何想法?

你永远不应该分享你的私钥。 您应该考虑您在此发布的密钥并生成新的密钥和签名请求。

您有证书请求,而不是实际签署的证书。 您向签署方提供请求(“CSR”)。 他们使用该请求来创建一个签名证书(“CRT”),然后他们可以提供给您。 关键是从不向任何人透露。

在线搜索SSL时遇到此问题:错误:0906D06C:PEM例程:PEM_read_bio:无起始行:预计:TRUSTED CERTIFICATE
运行后我得到这个错误:

  nginx -t 

我遇到的问题是cert.pem和cert.key丢失

  -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- 

仅供参考,您可以验证密钥只是调用:

 openssl x509 -noout -text -in your.crt openssl rsa -noout -text -in your.key 

在我的情况下,这个错误证明相当微妙:BEGIN块开始4破折号,而不是5---- vs ----- 。 可悲的是验证工具的错误信息不是很明确。

我错误地在gitlab.rb文件中配置了证书。 一个简单的错误花了很长时间才意识

 nginx['ssl_certificate'] = "/etc/gitlab/ssl/self-ssl.crt" nginx['ssl_certificate'] = "/etc/gitlab/ssl/self-ssl.key" 

代替

 nginx['ssl_certificate'] = "/etc/gitlab/ssl/self-ssl.crt" nginx['ssl_certificate_ key '] = "/etc/gitlab/ssl/self-ssl.key"