GNU/Linux >> Tutoriels Linux >  >> Panels >> Panels

Comment sécuriser Nginx avec Let's Encrypt sur Ubuntu 20.04

La sécurisation d'un site Web fonctionnant avec Nginx en tant que serveur Web peut être effectuée avec Let's Encrypt, et c'est pourquoi nous écrivons ce tutoriel pour vous.

Let's Encrypt est une autorité de certification qui fournit des certificats TLS/SSL gratuits valables 90 jours. SSL signifie Secure Sockets Layer et un certificat SSL est un certificat numérique qui permet une connexion cryptée et l'authentification de l'identité du site Web. Dans cet article de blog, nous utiliserons Certbot pour obtenir un certificat SSL gratuit pour Nginx.

L'installation du certificat SSL gratuit Let's Encrypt sur Ubuntu 20.04 avec Certbot est un processus simple et devrait prendre jusqu'à 10 minutes. Commençons !

Prérequis

  • Nouvelle installation d'Ubuntu 20.04
  • Privilèges utilisateur :utilisateur root ou non root avec privilèges sudo
  • Valide Un enregistrement du domaine pointant vers l'adresse IP de votre serveur (votredomaine.com et www.votredomaine.com)

Mettre à jour le système

Avant de commencer le processus d'installation, nous devons mettre à jour le système pour obtenir les derniers packages et mises à jour disponibles.

sudo apt update -y && sudo apt upgrade -y

Installer le serveur Web Nginx

Pour installer le serveur Web Nginx, exécutez les commandes suivantes :

sudo apt install nginx -y

Une fois l'installation terminée, activez et démarrez le service Nginx :

sudo systemctl enable nginx && sudo systemctl start nginx

Pour vérifier si tout est OK, vérifiez l'état du service :

sudo systemctl status nginx

Vous devriez recevoir le résultat suivant :

root@vps:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-02-06 19:34:56 UTC; 11s ago
       Docs: man:nginx(8)
    Process: 322857 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 322858 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 322859 (nginx)
      Tasks: 5 (limit: 4617)
     Memory: 5.0M
     CGroup: /system.slice/nginx.service
             ├─322859 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

Créer un hôte virtuel Nginx

Avant de poursuivre l'installation de Free Let's Encrypt, nous devons créer un fichier d'hôte virtuel contenant notre nom de domaine. Allez dans le répertoire de configuration de Nginx et créez le fichier.

cd /etc/nginx/conf.d/ && sudo nano yourdomain.com.conf

Collez les lignes de code suivantes.

server {
        listen 80;
        root /var/www/html;
        index  index.php index.html index.htm;
        server_name yourdomain.com;

        error_log /var/log/nginx/yourdomain.com_error.log;
        access_log /var/log/nginx/yourdomain.com_access.log;

        client_max_body_size 100M;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
}

Vérifiez la syntaxe de configuration Nginx si elle est OK.

nginx -t

Vous devriez recevoir le résultat suivant :

root@vps:/etc/nginx/conf.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Si vous recevez cette sortie, vous pouvez redémarrer le service Nginx et accéder à votre site Web.

sudo systemctl restart nginx

Installer Certbot

En ce moment, notre site Web fonctionne sur le protocole HTTP. L'installation du certificat SSL Free Let's Encrypt permettra à notre site Web de fonctionner en toute sécurité via le protocole HTTPS. Avant de commencer à obtenir le certificat, nous devons installer le certbot python pour Nginx.

sudo apt install certbot python3-certbot-nginx

Une fois que le certbot est installé avec succès, nous pouvons passer à l'étape principale de ce tutoriel sur l'obtention d'un certificat SSL.

Obtenir un certificat SSL

Pour exécuter le certbot avec le plugin Nginx en spécifiant le nom de votre domaine, exécutez la commande suivante :

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Après avoir exécuté cette commande, vous devrez remplir quelques entrées, telles que l'adresse e-mail, l'accord sur les termes et conditions, si vous souhaitez partager votre adresse e-mail ou non, et les options de redirection.

root@vps:~# sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yourdomain.com
http-01 challenge for www.yourdomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf

Si tout est configuré comme il se doit, le certificat sera installé et vous recevrez le message ci-dessous.

Congratulations! You have successfully enabled https://yourdomain.com and
https://www.yourdomain.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=yourdomain.com
https://www.ssllabs.com/ssltest/analyze.html?d=www.yourdomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/yourdomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/yourdomain.com/privkey.pem
   Your cert will expire on 2022-05-07. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Vous pouvez désormais accéder à votre site Web en toute sécurité à l'adresse https://votredomaine.com

Toutes nos félicitations! Vous avez réussi à sécuriser le Nginx avec le certificat SSL Free Let's Encrypt sur votre serveur Ubuntu 20.04.

Bien sûr, vous n'êtes pas obligé d'installer le certificat SSL par vous-même, et si vous utilisez l'un de nos services d'hébergement VPS SSD, auquel cas vous pouvez simplement demander à nos administrateurs système experts de l'installer pour vous et de sécuriser votre site Web. Ils sont disponibles 24h/24 et 7j/7 et prendront immédiatement en charge votre demande.

Si vous avez aimé cet article, sur la façon de sécuriser Nginx avec Lets Encrypt sur Ubuntu 20.04, partagez-le avec vos amis sur les réseaux sociaux en utilisant les boutons ci-dessous ou laissez simplement un commentaire dans la section des commentaires. Merci.


Panels
  1. Sécuriser Nginx avec Let's Encrypt sur Ubuntu 18.04 - Comment faire ?

  2. Comment sécuriser Nginx avec Letsencrypt sur Ubuntu 20.04

  3. Comment installer Joomla avec Nginx sur Ubuntu 18.04

  4. Comment installer Let's Encrypt sur Ubuntu 20.04 avec Apache

  5. Comment installer Gitea avec NGINX et Free Let's Encrypt SSL sur Ubuntu 20.04

Comment sécuriser Nginx avec le certificat SSL Let's Encrypt

Comment sécuriser le serveur LEMP avec Let's Encrypt Free SSL sur Ubuntu 18.04 VPS

Comment sécuriser Apache avec Let's Encrypt sur CentOS 8

Comment sécuriser Nginx avec Let's Encrypt sur CentOS 8

Comment sécuriser Nginx avec Let's Encrypt sur Ubuntu 20.04

Comment sécuriser Apache avec Let's Encrypt sur Ubuntu 20.04