Introduction
In this article, we will guide you through the steps of installing an SSL certificate on the Nginx web server in the CentOS/Ubuntu Operation System.
We assume that you have Nginx installed on your server and uploaded certificate files (.crt file and .key file) to your Linux server.
1 Edit virtual host configuration file
1.1 Open the configuration file of virtual host
Open the configuration file of the virtual host. The path to the configuration file is usually as follows:
/etc/nginx/sites-available/your_domain_name.vhost
1.2 Add the related SSL certificate information
Add the following command lines to the end of the configuration file to update your SSL information:
server {
listen 443 ssl;
server_name ssl.xxx.ml; # Your domain name
# The path of the .crt file of your SSL certificate
ssl_certificate /path/to/your_domain_name.crt;
# The path of the .key file of your SSL certificate
ssl_certificate_key /path/to/your_domain_name.key;
}
-
2 Restart Nginx service
# systemctl restart nginx
3 Test the HTTPs of your website
4 Add redirection from HTTP to HTTPS
Edit the configuration file ‘vi /etc/nginx/sites-available/your_domain_name.vhost’ and add the following command line to the file, as shown in the screenshot.
rewrite ^(.*)$ https://$server_name$1 permanent;
5 Restart Nginx service
# systemctl restart nginx
Article ID: 733, Created: January 15, 2021 at 1:54 AM, Modified: February 24, 2021 at 11:14 PM