nginx: [emerg] SSL_CTX_use_PrivateKey_file("/etc/nginx/ssl/mydomain.key") failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: ANY PRIVATE KEY error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib)
#HTTPS server configuration
server {
listen 443;
listen [::]:443;
ssl on;
ssl_certificate /etc/nginx/mydomain.chained.crt;
ssl_certificate_key /etc/nginx/mydomain.key;
root /var/www/html;
server_name mydomain;
location / {
try_files $uri $uri/ =404;
}
}
Today I hit this exact problem and solved it too. Solution was to open the private key file in Notepad++ and change encoding to ANSI and then upload to server and use it.
In case anyone else encounters this, @aCid was right. The problem for me was the encoding on the .key file.
I used GoDaddy and had them generate the private key for me (then downloaded it). It turns out that it was encoded as UTF-8. This doesn't work for NGINX. You needed it encoded in ASCII.
Since this was already on my server and I was accessing it via SSH, I simply:
UTF-8)vi newfile.key).After that everything worked fine.