Configuring SSL certificate(HTTPS)
A website needs an SSL certificate to keep user data secure, verify ownership, prevent attackers from creating a fake version of the site, and gain user trust.
This document introduces how to get and use an SSL certificate (HTTPS) for your application.
Get an SSL Certificate from a Certificate Authority
You can get a SSL certificate from a certificate authority (CA) such as Let's Encrypt or Cloudflare and so on.
Once you have a certificate, you need to configure your web server to use it. The following references show how to configure your web server to use a certificate.
- Host ASP.NET Core on Linux with Apache: HTTPS configuration
- Host ASP.NET Core on Linux with Nginx: HTTPS configuration
- How to Set Up SSL on IIS 7 or later
How to get a free SSL certificate from Let's Encrypt?
Let's Encrypt is a free, automated, and open certificate authority (CA). It gives the digital certificates to enable HTTPS (SSL/TLS) for websites. To get a free SSL certificate, we will use acme.sh and Cloudflare DNS API to get a free SSL certificate from Let's Encrypt.
If you have any problem with the following steps, you can read the acme.sh tutorial.
Install acme.sh
Ensure that you have curl
command in your terminal. And run the following command on your terminal:
Cloudflare DNS API token
You will need to create an API token which either:
(i) has permission to edit a single specific DNS zone; or (ii) has permission to edit multiple DNS zones.
You can do this via your Cloudflare profile page under the API Tokens section. When you create the token, under Permissions, select Zone > DNS > Edit, and under Zone Resources, only include the specific DNS zones within which you need to perform ACME DNS challenges.
The API token is a 40-character string that may contain uppercase letters, lowercase letters, numbers, and underscores. You must provide it to acme.sh by setting the environment variable CF_Token to its value, e.g. run export CF_Token="Y_jpG9AnfQmuX5Ss9M_qaNab6SQwme3HWXNDzRWs".
(i) Single DNS zone You must give acme.sh the zone ID of the DNS zone it needs to edit. This is a 32-character hexadecimal string (e.g. 763eac4f1bcebd8b5c95e9fc50d010b4), and should not be confused with the zone name (e.g. example.com). This zone ID can be found via the Cloudflare dashboard on the zone's Overview page in the right-hand sidebar.
You provide this info by setting the environment variable CF_Zone_ID to this zone ID, e.g. run export CF_Zone_ID="763eac4f1bcebd8b5c95e9fc50d010b4".
(ii) Multiple DNS zones You must give acme.sh the account ID of the Cloudflare account to which the relevant DNS zones belong. This is a 32-character hexadecimal string, and should not be confused with other account identifiers, such as the account email address (e.g. alice@example.com) or global API key (which is also a 32-character hexadecimal string). This account ID can be found via the Cloudflare dashboard, as the end of the URL when logged in, or on the Overview page of any of your zones, in the right-hand sidebar, beneath the zone ID.
You provide this info by setting the environment variable CF_Account_ID to this account ID, e.g. run export CF_Account_ID="763eac4f1bcebd8b5c95e9fc50d010b4".
Issue a certificate
Convert the certificate to PFX format(IIS format)
If you want to set a password for the PFX file, you can set the password with -passout pass:your_password
.
Common Exceptions
If you encounter the following exceptions, it means your certificate is not trusted by the client or the certificate is not valid. You will may see the following SSL certificate errors in your browser when you try to access the website.