SSL certificates allow websites to switch from HTTP to HTTPS. This is safer. An SSL certificate is a file that is stored on a website's source server. SSL certificates enable SSL/TLS encryption.
They contain the website’s public key, website identity, and other information. To verify the identity of the origin server, devices will refer to this file when they attempt to communicate with it. The private key is kept confidential and protected.
So, let's get started
In order to install the SSL certificate on your NGINX web server, you need to have an NGINX installed on ubuntu 21.04. we are going to use Alibaba ECS Instance for this guide.
If you don't have NGINX installed on your server you can follow this guide -
How to install NGINX on Ubuntu 21.04
First of all, connect your instance via SSH. You can connect by using this command.
ssh username@your-public-ip-address
Create a Config file same as Default Config which is by default given by Nginx. Include your complete domain name. This will ensure that there is no syntax error.
You can use this command to copy the existing config file to the new one.
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/www.example.com
Now open the file with nano editor ( you can use whatever you want) by using this command
sudo nano /etc/nginx/sites-available/www.example.com
Replace www.example.com
with your domain name.
Now to save this file press CTRL+X
, Y
, and Enter
.
In order to use your new NGINX configuration file, we have to unlink the default configuration file.
You can do that by using this command
sudo unlink /etc/nginx/sites-enabled/default
Next, we have to create a symlink to the NGINX-enabled directory. We can create this symlink by typing:
sudo ln -s /etc/nginx/sites-available/www.example.com /etc/nginx/sites-enabled/www.example.com
After editing all these configurations we have to make sure that there is no syntax error.
we can confirm that by using this command
sudo nginx -t
We can now restart our NGINX web server to make those changes effective
sudo systemctl restart nginx
In order to use HTTPS ( SSL Certificate ), we have to allow 443
port in our firewall.
Make sure you enabled 443
port.
Certbot is an open-source software tool that automatically enables HTTPS using Let’s Encrypt certificates.
To install certbot on ubuntu we can use this command :
sudo apt install certbot python3-certbot-nginx
Press Y
to confirm it
NGINX's Certbot plugin reconfigures Nginx, and reloads its configuration when necessary. The NGINX plug-in is all you need to generate certificates.
We can use this command to generate SSL certificate
sudo certbot --nginx -d example.com -d www.example.com
It will ask you to enter your mail ID where you will get the SSL expiry-related information.
Now Agree with the term and conditions.
Finally, the output displays that you have successfully generated a certificate and specifies the location of the certificate on your server.
SSL certificate should be installed on your NGINX web server. if you have any questions regarding this, please let us know in the comment section.
Thank You!
How to Install LAMP ( Linux, Apache, MySQL and PHP ) Stack on Ubuntu 20.04 LTS
Alibaba Clouder - November 19, 2019
Alibaba Clouder - January 9, 2020
Alibaba Clouder - August 22, 2018
Alibaba Clouder - August 27, 2020
Alibaba Clouder - May 11, 2018
Alibaba Clouder - May 29, 2018
You can use Certificate Management Service to issue, deploy, and manage public and private SSL/TLS certificates.
Learn MoreElastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn MoreAn elastic and horizontally scalable high-performance computing service providing the same computing performance as traditional physical servers including physical isolation.
Learn More