How to configure signed SSL certificates with aspnet core 3.1 on hosted in Kestrel/linux

Viewed 2353

I managed to get a letsencrypt signed certificate to enable SSL for my domain on the host properly. Now I do not understand how to bind it to my application running on ubuntu:

I used the following to set-up the private key:

webBuilder.UseKestrel((hostingContext, options) =>
{
   options.ListenAnyIP(443, loptions => loptions.UseHttps("/etc/letsencrypt/live/mydomain.com/privkey.pem"));
});

The server mode SSL must use a certificate with the associated private key

It is not clear to me how to bind the public and private keys and use it remotely without the use of apache or nginx.

1 Answers

You first need to convert your private key and certifcate to pfx certificate using OpenSSL :

openssl pkcs12 -inkey privatekey.pem -in mycert.cert -export -out mycertificate.pfx

Then, you can use it this way in your appsettings.json file for Kestrel :

"Kestrel": {
    "EndPoints": {
      "HttpsDefaultCert": {
        "Url": "https://*:443"
      },
      "Http": {
        "Url": "http://*:80"
      }
    },
    "Certificates": {
      "Default": {
        "Path": "mycertificate.pfx",
        "Password": "MyCertificatePassword"
      }
    }
  }
Related