Let’s Encrypt is a Certificate Authority (CA) that makes it easy to obtain free TLS/SSL certificates, enabling HTTPS on web servers.
This tutorial explains how to install NGINX as a web server on Ubuntu and then add a certificate with Let’s Encrypt. It then explains how to automatically renew your SSL certificate. Throughout this process, we will use Ubuntu 22.04 LTS as root, although the procedure also works on later versions of Ubuntu.
Remember that the preinstalled image of LEMP (Linux, Nginx, MySQL, and PHP) is available on Clouding; you can use it to create a web server with NGINX without installing it manually.
Requirements
Before continuing with this tutorial, you must have root access to the VPS server. You must also have a domain/DNS record pointing to your server on Clouding. In addition, the domain must have an A record for the certificate creation process to work correctly.
If you want to create a certificate for more than one DNS record, for example, example.com and www.example.com you must create both records on the domain’s name servers.
Installing the Nginx web server
The first step is to install Nginx:
# apt-get install nginxNext, start it and enable it to start at system boot:
# systemctl start nginx && systemctl enable nginxNginx configuration
Now configure the web space that will hold your website configuration. You can create a copy of the default configuration:
# cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com.confThen edit the configuration file you created:
# nano /etc/nginx/sites-available/example.com.confTo change the web directory path in the root parameter and add the DNS names to server_name:
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/html/example.com/www;Save the changes and create the web directory:
# mkdir -p /var/www/html/example.com/wwwOnce it has been created, enable the NGINX site configuration:
# ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabledThen check the configuration; it should display "syntax is ok":
# nginx -tFinally, if the check succeeds, complete the NGINX configuration by restarting it so that the changes take effect:
# systemctl restart nginxInstalling and configuring Let’s Encrypt with Nginx
Now configure Nginx to obtain the certificate created by Certbot so that you can use the certificates provided by Let’s Encrypt. The following article explains how to obtain a certificate and install it in NGINX:
The procedure is summarized below:
Installing Certbot for NGINX:
First, you will need to install the packages required by Certbot:
# apt update && apt install python3-certbot-nginx -yObtaining the SSL certificate and configuring it automatically:
To obtain the certificate and automatically modify the NGINX configuration, run the following command, replacing the example DNS names and/or adding more if necessary:
# certbot --nginx -d example.com -d www.example.comConfirm that automatic configuration was successful by accessing your domain over HTTPS in a browser and checking that a valid certificate is displayed. You can also use SSL Checker or an SSL Server Test to verify the Let's Encrypt certificate.
Certificate renewal
If you have followed this procedure, Certbot itself will handle automatic renewal of the certificate, so you do not need to worry about it (you can find more information in the article linked above).
We hope this tutorial has helped you 🙂. Remember, if you have any questions about this or anything else related to your servers on Clouding, feel free to email soporte@clouding.io We’re here for whatever you need!