LINUX

Cómo configurar Nginx con Let’s Encrypt en Ubuntu 20.04

Para habilitar la comunicación segura (es decir, HTTPS) en su servidor web NGINX, debe obtener un certificado SSL / TLS de una autoridad certificadora de confianza. Vamos a cifrar es una autoridad de certificación sin fines de lucro que ofrece certificados SSL / TLS gratuitos.

Este tutorial describe cómo configurar un certificado SSL / TLS gratuito emitido por Let’s Encrypt en Ubuntu 20.04 Servidor LTS en ejecución Nginx.

Requisitos previos:

Instalar Certbot en Ubuntu

Certbot es una herramienta de código abierto que simplifica y automatiza el proceso de obtención y renovación de certificados de Let’s Encrypt. Vamos a instalar Certbot utilizando el sistema de implementación Snap. Snap está preinstalado en Ubuntu 20.04.

Actualizar snapd

Ejecute los siguientes comandos para actualizar snapd.

$ sudo snap install core
$ sudo snap refresh core

Instalar certbot snap

A continuación, estamos listos para instalar el complemento Certbot.

Nota: Si ya instaló Certbot con el comando apt estándar, primero ejecute el siguiente comando para eliminarlo. Esto asegurará que el complemento Certbot funcione correctamente.

$ sudo apt-get remove certbot
$ sudo snap install --classic certbot
certbot 1.11.0 from Certbot Project (certbot-eff✓) installed

Habilitar el comando certbot

Después de instalar con éxito el complemento Certbot, ejecute el siguiente comando para habilitar certbot para usar.

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

Obtenga su certificado

Cuando ejecute el siguiente comando, certbot lo guiará por el resto del proceso. Certbot también actualiza su configuración de NGINX automáticamente para activar HTTPS.

$ sudo certbot --nginx

A continuación se muestra un resumen de lo que certbot le pedirá que haga durante este proceso.

  1. Proporcione una dirección de correo electrónico a la que se enviarán los avisos de renovación y seguridad.
  2. Ingresar y aceptar los términos de servicio
  3. Ingresar y o norte aceptar o negarse a compartir su dirección de correo electrónico con los desarrolladores de Certbot
  4. Confirme los nombres de dominio para los que le gustaría habilitar HTTPS

Producción

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): shola@linoxide.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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
Account registered.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: domain1.com
2: www.domain1.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 
Requesting a certificate for domain1.com and www.domain1.com
Performing the following challenges:
http-01 challenge for domain1.com
http-01 challenge for www.domain1.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/domain1
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/domain1
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/domain1
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/domain1

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/domain1.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/domain1.com/privkey.pem
   Your certificate will expire on 2021-04-10. 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"
 - 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

Cerbot agregará las siguientes entradas (oraciones que se muestran administradas por Certbot) en el archivo de bloque nginx.

/ etc / nginx / sites-enabled / domain1

$ cat /etc/nginx/sites-enabled/domain1
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {

       server_name domain1.com www.domain1.com;

       root /var/www/domain1.com;
       index index.html;

       location / {
               try_files $uri $uri/ =404;
       }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = www.domain1.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = domain1.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


       listen 80;
       listen [::]:80;

       server_name domain1.com www.domain1.com;
    return 404; # managed by Certbot
}
$

Explore su sitio web para confirmar que ahora se muestra el icono de candado.

Proceso de renovación de certificados

Los certificados emitidos por Let’s Encrypt tienen una validez de 90 días. Durante la instalación, certbot crea una tarea programada para renovar automáticamente sus certificados antes de que caduquen. Siempre que no cambie la configuración de su servidor web, no tendrá que volver a ejecutar certbot.

Ejecute el siguiente comando para probar el proceso de renovación automática.

$ sudo certbot renew --dry-run

Conclusión

En esta guía, aprendimos cómo configurar vamos a cifrar el certificado SSL en el servidor web NGINX que se ejecuta en Ubuntu 20.04.

En lugar de Cerbot, también puede utilizar CUMBRE Script de shell para emitir y renovar automáticamente los certificados gratuitos de Let’s Encrypt.

Si algo no está claro, háganoslo saber en la sección de comentarios a continuación.

Publicaciones relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Botón volver arriba
Cerrar