Connect to your cloud server with SSH for this exercise.
Provision an SSL certificate using Certbot by Let's Encrypt
The goal of this exercise is to provision a Letโs Encrypt SSL certificate for an application deployed in previous exercises using Certbot.
This exercise assumes that you have deployed at least one web site or application during previous exercises, and that you have configured nginx to serve it.
Legend
Parts of this exercise are annotated with the following icons:
-
A task you MUST perform to complete the exercise -
An optional step that you may perform to make sure that everything is working correctly, or to set up
additional tools that are not required but can help you
-
The end of the exercise -
The architecture of the software you ran or deployed during this exercise. -
Troubleshooting tips: how to fix common problems you might encounter
Install Certbot
Install Certbot with the following command:
$> sudo apt install certbot python3-certbot-nginx
Obtain a TLS certificate from Letโs Encrypt
Follow the instructions for nginx and Linux (snap) starting at step 6:
When the instructions ask you to โChoose how youโd like to run Certbotโ, you can choose the simplest option which is to โget a certificate and have Certbot edit your Nginx configuration automatically to serve itโ.
Once you are done, your web site or application should be accessible over HTTPS.
You should take a look at your nginx site configuration file(s) in the
/etc/nginx/sites-available directory, to see the changes Certbot has made.
What have I done?
You have run Certbot to request a TLS certificate from the Letโs Encrypt certificate authority (CA).
Before issuing a certificate, Letโs Encrypt (or any other certificate authority) requires domain validation, i.e. you must provide some proof that you control the server reachable at the certificateโs domain name. Since you have run Certbot on your server, it has automatically provided that proof by asking Letโs Encrypt to perform an HTTP challenge, and then completing the challenge by providing the appropriate file through nginx.
Certbot saved the certificate it obtained from Letโs Encrypt somewhere into the
/etc/letsencrypt directory. It then modified your nginx siteโs configuration
file to use that certificate.
Certbot has been able to automatically do all these things for you because you
have run it with administrative privileges by prefixing it with sudo.
Because the modified nginx configuration for your site now listens on port 443
for HTTPS and provides a valid TLS certificate, your todolist is now accessible
with an https:// instead of an http:// URL, and the TLS protocol is used to
encrypt communications between your browser and the server.
Architecture
This is a simplified architecture of the main running processes and communication flow at the end of this exercise:

This diagram shows the processes involved in all previous exercises, meaning those related to the PHP todolist and the revprod applications.
The only thing that has changed in this exercise is that you are now accessing your applications over an encrypted HTTPS/TLS connection instead of insecure HTTP.
Troubleshooting
Hereโs a few tips about some problems you may encounter during this exercise.
No names were found in your configuration files
If Certbot tells you that โNo names were found in your configuration filesโ but
you have nginx sites that are configured, this may be because you have an
underscore character (_) in your subdomains, e.g. jde.archidep.ch.
Although many tools support it, underscore are technically not allowed in domain names. You will have to change your subdomain for Certbot to recognize it as valid.
There are two things you need to do:
-
Log back into Gandi.net and add a new A record for your Azure VM just like you did during the Domain name configuration exercise.
Use something short like
jdeand*.jde(as long as it does not conflict with anyone elseโs subdomain), with the same IP address as before (the public IP address of your Azure VM). -
Replace your old subdomain by the new one in all your nginx configuration files, for example:
$> sudo nano /etc/nginx/sites-available/clock $> sudo nano /etc/nginx/sites-available/revprod $> sudo nano /etc/nginx/sites-available/todolistThen test and reload the nginx configuration with:
$> sudo nginx -t $> sudo nginx -s reload
Make sure your sites work at their new address. If they do, the certbot
command should now also detect them.
It may take a few minutes for the new DNS entries to propagate. If you are sure the new DNS entries are correct but it doesnโt work, try again a little while later.