Comment configurer HTTPS sur votre serveur Web à l'aide de Let's Encrypt
J'ai récemment mis en place un VPS sur DigitalOcean à l'aide du droplet officiel Node.js, qui installe Ubuntu Linux avec Node et Nginx en tant que proxy inverse, ce qui signifie qu'il s'agit d'un intermédiaire entre les utilisateurs et vos applications Node.js.
Par défaut, le droplet est configuré pour utiliser HTTP, mais nous voulons que nos applications soient servies à l'aide de HTTPS, la version sécurisée de HTTP.
Nous devons donc faire une petite procédure qui consiste à utiliserCertbotpour obtenir un certificat SSL viaCrypteronset configurer Nginx pour l'utiliser.
Voici les étapes que nous suivrons:
- Installez Certbot et le package Certbot Nginx
- Configurer Nginx
- Générer le certificat SSL à l'aide de Certbot
Installez Certbot et le package Certbot Nginx
Ces instructions supposent que vous utilisez Ubuntu, Debian ou toute autre distribution Linux utilisantapt-get
pour gérer les packages:
sudo apt-get install certbot python3-certbot-nginx
Configurer Nginx
Éditer/etc/nginx/sites-available/default
pour définir le nom de serveur correct (essentiel pour SSL)
sudo nano /etc/nginx/sites-available/default
trouver la ligneserver_name
et entrez votre nom de domaine:
server_name my.domain.com;Now run
sudo systemctl reload nginxto reload Nginx with the updated configuration.
The firewall should already be configured to accept HTTPS, find it out typing sudo ufw status
. You should see Nginx Full
in the list. If you only see Nginx HTTP
, look up how to change that.
Generate the SSL certificate using Certbot
Now we can invoke Certbot to generate the certificate. You must run this as root:
sudo certbot --nginx -d my.domain.com
(of course, change my.domain.com
to your domain name)
Enter your real email, as that will be used to communicate you any problem.
I also suggest to choose the option to redirect HTTP to HTTPS automatically.
That’s it!
SSL certificates are valid for 90 days, and Certbot is already set up for automated renewal. To simulate and test-drive the renewal process, run:
sudo certbot renew --dry-runThis should give you a successful message.
That’s it, now your Node apps should successfully run on HTTPS with no additional changes on your part.
More network tutorials:
- Introduction to WebSockets
- How HTTP requests work
- The HTTP Request Headers List
- The HTTP Response Headers List
- HTTP vs HTTPS
- What is an RFC?
- The HTTP protocol
- The HTTPS protocol
- The curl guide to HTTP requests
- Caching in HTTP
- The HTTP Status Codes List
- What is a CDN?
- The HTTP/2 protocol
- What is a port
- DNS, Domain Name System
- The TCP Protocol
- The UDP Protocol
- An introduction to REST APIs
- How to install a local SSL certificate in macOS
- How to generate a local SSL certificate
- How to configure Nginx for HTTPS
- A simple nginx reverse proxy for serving multiple Node.js apps from subfolders
- What is a reverse proxy?