Install an SSL certificate on Node.js (Linux)
You can enable HTTPS access for a domain name configured on your Simple Application Server. This upgrades your data transmission protocol from HTTP to HTTPS at a low cost. HTTPS provides website authentication and encrypted data transmission to protect your data in transit from tampering and leakage. This topic shows you how to install an SSL certificate and enable HTTPS access on a Simple Application Server running a Node.js runtime environment.
Prerequisites
-
You have a domain name. For more information about how to purchase a domain name from Alibaba Cloud, see Register a generic domain name.
-
If your Simple Application Server is in the Chinese mainland, ensure your domain name has an Internet content provider (ICP) filing. For more information, see What is an ICP filing?.
-
Your domain name has been bound to the Simple Application Server and resolved. For more information, see Register and resolve a domain name.
Background
Node.js is a JavaScript runtime built on Chrome's V8 engine for building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight and efficient. It is well-suited for data-intensive, real-time applications that run on distributed devices. For more information, visit the official Node.js website.
When you purchase, apply for, and deploy a certificate to your web server with Certificate Management Service, your web service can transmit data over HTTPS. HTTPS establishes an SSL-encrypted channel between a client's browser and the web server. This provides strong, one-way encryption to prevent data leaks or tampering. HTTPS encryption is essential for mobile apps, mini programs, and other code or controls published to an app store or an application ecosystem. HTTPS provides the following benefits for your website:
-
Security and compliance: Meet the requirements of various app stores and application ecosystems.
-
Encrypted data transmission: Encrypt communications between your website and its users to prevent data hijacking, tampering, and interception.
-
Enhanced website security: Prevent phishing events. Browsers display a security indicator for HTTPS-secured sites, improving your website's credibility, traffic, and search engine ranking.
For more information, see What is Certificate Management Service?.
Step 1: Create a Node.js server
-
Go to the Servers page in the Simple Application Server console.
-
On the Simple Application Server purchase page, configure the resources.
For more information, see Create a Simple Application Server.
In the Image section, select the Node.js 14.15.2 application image.
Step 2: Apply for an SSL certificate
You can use Alibaba Cloud to apply for free certificates, paid certificates, or certificates from other service providers. We recommend using free certificates for testing or personal trials. You cannot apply for free certificates for domain names with special top-level domains (TLDs), such as .org and .jp. For production environments, we recommend that you use paid commercial certificates. This topic describes how to apply for a free certificate. To purchase a commercial certificate, see Purchase a commercial certificate.
-
In late June 2024, Certificate Management Service renamed SSL free certificates to Individual Test Certificate (Free) and changed upgraded certificates (valid for 12 months) to Individual Test Certificate (Pro). For more information about the renaming of free certificates, see [Notice] Renaming of Free Certificates.
-
Each Alibaba Cloud individual or enterprise account (subject to real-name verification) can apply for a package of 20 free certificates once per calendar year. A calendar year runs from January 1 to December 31. The unused quota in your free certificate package is cleared at 24:00:00 on December 31 each year. You must wait until 00:00:00 on January 1 of the next year to claim the free certificate package for that year. For more information about the use cases, quota rules, and limitations of free certificates, see Description of Individual Test Certificates.
Purchase a free SSL certificate
-
Log on to the Certificate Management Service console.
-
In the left-side navigation pane, choose .
-
On the Individual Test Certificate (Formerly Free Certificate) tab, click Buy Now.
-
In the Buy Now panel, purchase an Individual Test Certificate as described in the following table. Read and select Certificate Management Service Terms of Service and Technical Support Agreement for Certificate Management Service. Click Buy Now and complete the payment.
Parameter
Description
Example
Service
-
SSL Certificate: The entry point for purchasing commercial certificates. For more information about the parameters, see Purchase a commercial certificate.
-
Individual Test Certificate: Generally used for testing and personal trials.
For more information about the differences between commercial certificates and individual test certificates, see Description of Individual Test Certificates.
Individual Test Certificate
Certificate Type
-
Individual Test Certificate (Free): A free certificate that is valid for 3 months after it is issued.
-
Individual Test Certificate (Pro): This certificate costs CNY 68 per year. The certificate is valid for 12 months after it is issued.
Individual Test Certificate (Free)
Service
This parameter is available only for Individual Test Certificate (Free).
NoteThe stability of the Online Certificate Status Protocol (OCSP) is not guaranteed for individual test certificates.
Keep the default setting.
Quantity
-
Individual Test Certificate (Free): The default value is 20.
Each Alibaba Cloud individual or enterprise account (subject to real-name verification) can apply for 20 free individual test certificates once per calendar year. For more information about the use cases, quota rules, and limitations of free individual test certificates, see Description of Individual Test Certificates.
Note-
A calendar year runs from January 1 to December 31. The unused quota in your free certificate package is cleared at 24:00:00 on December 31 each year. You must wait until 00:00:00 on January 1 of the next year to claim the free individual test certificate package for that year.
-
If you have used up the 20 free individual test certificates within a calendar year, you can purchase an Individual Test Certificate (Pro) or an HTTPS acceleration gateway. For more information, see Upgrade an individual test certificate. You can also purchase a commercial certificate. For more information, see Purchase a commercial certificate.
-
-
Individual Test Certificate (Pro): You can purchase a minimum of 1 and a maximum of 100 certificates at a time.
Keep the default setting.
Other services
Certificate application assistance and deployment services help you resolve issues when using SSL certificates. The services help you prepare application materials and coordinate with CAs to ensure your certificates are issued as quickly as possible. If you are unable to install or configure certificates, experts can provide remote video guidance to help you quickly identify and resolve technical issues. For more information, see Purchase certificate application assistance and deployment services.
-
Not Required
-
Assistance Application: helps you quickly issue an SSL certificate during business hours (09:00 to 18:00).
-
Deployment: helps you deploy an RSA or ECC certificate during business hours (09:00 to 18:00).
-
Assistance Application + Deployment: provides end-to-end assistance for certificate application and deployment. This service is also available on non-business days (09:00 to 18:00) to help you quickly issue and deploy the certificate.
Not Required
-
Submit a free certificate application
Log in to the Certificate Management Service console.
In the navigation pane on the left, choose .
-
On the SSL Certificates page, click the Individual Test Certificate (Formerly Free Certificate) tab.
-
On the Individual Test Certificate (Formerly Free Certificate) tab, click Create Certificate.
-
In the Create Certificate panel, configure the parameters as described in the following table, select Quick Issue, and then click OK.
Parameter
Description
Certificate Type
Select Individual Test Certificate (Free).
Remaining Certificate Quota/Total
The number of remaining certificates out of your total quota. You can apply for a certificate only if the remaining quota is not 0.
Domain Name
The domain name that the certificate will protect.
When you apply for an individual test certificate, you can enter only a single domain name, such as
aliyundoc.com.Important-
You cannot apply for an Individual Test Certificate for a domain name that uses a special top-level domain (TLD), such as
.edu,.gov,.org,.jp,.pay,.bank,.live,.nuclear, and.ru. This limitation does not apply to commercial certificates. To apply for a certificate for a domain name with a special TLD, you must apply for a commercial certificate. -
You cannot apply for individual test certificates for public IP addresses. Only OV single-domain certificates from the GlobalSign, DigiCert, GeoTrust, vTrus, and CFCA brands can be bound to IP addresses. For more information, see Purchase a commercial certificate.
-
To apply for certificates for multiple domain names in a single operation, you must purchase a commercial certificate. For more information, see Purchase a commercial certificate.
Quantity
The number of certificates. The default value is 1. You cannot increase the value.
Quick Issue
NoteSelecting Quick Issue lets you enter the certificate application information and submit it in the current step.
Domain Verification Method
-
If the DNS records for your domain are managed in your current Alibaba Cloud account, Certificate Management Service automatically detects the account and selects Automatic DNS Verification by default. You cannot change this setting. After you submit the application, the system automatically performs DNS verification.
-
If the DNS records for your domain are managed in a different account, you can select one of the following methods to verify domain ownership:
-
Manual DNS Verification: You must manually modify the DNS records of the domain name and add a DNS record to the domain name console to verify the ownership of the domain name.
-
Automatic Verification (Domain Name-level Authorization): You must manually add a CNAME record on the console of your DNS service provider to verify the ownership of the domain name. After you add the record, you can select this verification method when you apply for SSL certificates for the domain name in the future. You do not need to add another DNS record. For more information, see Verify the ownership of a domain name.
-
File Verification: You must manually download a dedicated verification file from the Certificate Management Service console and upload the file to the specified verification directory on the server.
-
Contact
Select the contact for this certificate application. The contact information includes an email address and a mobile phone number. To create or modify a contact, click Create Contact or Edit, or go to Contact Management.
ImportantAfter the CA receives the certificate application, it sends a validation email to the contact's email address or communicates with the contact using their mobile phone number (only in the Chinese mainland) for the review. Make sure that the contact information is accurate and valid.
Location
Select the city or region where the applicant is located.
Encryption Algorithm
The encryption algorithm of the certificate.
RSA is selected by default and cannot be changed. RSA is the most widely used asymmetric encryption algorithm in the world and provides good compatibility.
CSR Generation
A Certificate Signing Request (CSR) is a file that you submit to a certificate authority (CA) to apply for an SSL certificate. It contains your domain name, organization information, and public key. You must keep the corresponding private key secure.
Automatic
Alibaba Cloud automatically creates a CSR and a private key. After the certificate is issued, you can download the full certificate file that includes the private key.
Manual entry
Use a tool like OpenSSL or Keytool to generate a CSR and a private key. You must keep the private key file secure. Then, copy the CSR content into the CSR File field. For more information about how to create a CSR and a private key file, see How do I create a CSR file?.
Important-
Keep your private key secure. If the private key is lost, you cannot use the certificate on your server. The private key cannot be recovered. You must generate a new key pair and re-apply for the certificate.
-
If you apply for a national cryptography (GM) certificate and select Manual Entry for the CSR, the private key is not stored in Alibaba Cloud. The encrypted certificate must be decrypted by using the private key. You must contact the party that generated the private key to assist with decryption (except for Wosign certificates).
-
The encryption algorithm of the CSR must be the same as the encryption algorithm that you selected. If you do not know the encryption algorithm that is used by the CSR, you can use the View CSR tool to check it. For more information, see View CSR details.
-
Certificates that are issued by using this method cannot be deployed to other Alibaba Cloud services with one click.
Existing CSR
Select a CSR that matches the Domains to Bind from the CSRs that have been created or uploaded on the Certificate Management Service console. For more information about how to create and upload a CSR, see Create a CSR.
CSR File
This parameter is required only when CSR Generation is set to Manual or Select Existing CSR. Enter the content of your CSR file.
-
-
Follow the prompts in the Verify Information section to complete domain ownership verification.
After domain ownership verification succeeds, the certificate is typically issued within 1 to 15 minutes. After the certificate is issued, its Status changes to Issued. If certificate issuance takes a long time, check whether the DNS verification settings are correct. For more information about domain ownership verification and common errors, see Verify the ownership of a domain name.
NoteIf you do not select Quick Issue, submitting the application only creates a certificate entry. You must then click Apply for Certificate in the certificate's Actions column, enter the application information, submit it for review, and complete the verification described in this step.
Step 3: Configure the SSL certificate
After a certificate is issued, its status changes to Issued. You must download and configure the certificate. For more information, see Deploy an SSL certificate.
-
Download the certificate.
-
On the Commercial Certificates or Individual Test Certificate (Formerly Free Certificate) tab, select the certificate that you want to download, and then click Download in the lower-left corner of the certificate list.
NoteYou can click Download only for SSL certificates in the Issued, Expiring, or Expired state.
-
In the Batch Download Certificates dialog box, download the certificate for your server type.
This example uses NGINX for forwarding, so you need to download the NGINX version.
WarningAfter downloading the certificate, save it in a secure location to prevent a certificate leak.
In the Batch Download Certificates dialog box, find the NGINX row (format: pem/key), and then click Download in that row.
-
After decompressing the package, you get two files:
drxxxcn.key drxxxcn.pem
-
-
Use a tool such as WinSCP or Xshell to upload the private key file (.key) and the certificate file (.pem) to a specified directory on the Simple Application Server, such as /home.
-
Connect to the Simple Application Server. For more information, see Connect to a Linux server.
-
Run the following commands to create an https_server_test.js file.
cd /home sudo touch https_server_test.js -
Run the following command to edit the https_server_test.js file.
vim https_server_test.jsPress the i key to enter insert mode, and then add the following content to the https_server_test.js file:
// The https package is required to start an HTTPS service. // The fs package is required to read files. const https = require('https'); const fs = require('fs'); // Read the certificate files into the options object. // Use the readFileSync() method to sequentially read the files and start the service. const options = { key: fs.readFileSync('/home/cert-file-name.key'), cert: fs.readFileSync('/home/cert-file-name.pem') }; // Create and start the server, and set the listening port number. https.createServer(options, (req, res) => { res.end('hello world\n'); }).listen(443);Where:
-
/home/cert-file-name.key: The absolute path to the private key file you uploaded.
-
/home/cert-file-name.pem: The absolute path to the SSL certificate file you uploaded.
ImportantIncorrect certificate file paths will cause the configuration to fail and prevent HTTPS access.
-
-
After adding the content, press the
Esckey to exit insert mode. Then, enter:wqand press theEnterkey to save the file and exit. -
Run the following command to start the HTTPS server.
sudo node https_server_test.js -
Open a browser and visit
https://<your_domain_name>.-
A lock icon in the browser's address bar indicates a successful configuration. The page returns the expected content, such as
hello world. -
If your website is not accessible over HTTPS, verify that port 443 is enabled on your Simple Application Server and is not blocked by other tools. To open port 443, see Manage firewalls.
-