Cómo configurar Nginx con Let’s Encrypt en Ubuntu 20.04 | Ubuntu 20.10
Para habilitar la comunicación segura (es decir, HTTPS) en su servidor web NGINX, debe obtener un certificado SSL/TLS de una autoridad de certificación de confianza. Let’s Encrypt 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 LTS Server que ejecuta Nginx .
requisitos previos:
- Servidor Ubuntu 20.04 instalado con Nginx y sitio web alojado
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 complemento
Ejecute los siguientes comandos para actualizar snapd.
$ sudo snap install core
$ sudo snap refresh core
Instalar complemento de certbot
A continuación, estamos listos para instalar el complemento Certbot.
Nota: Si ya instaló Certbot con el comando apt estándar, ejecute primero el siguiente comando para eliminarlo. Esto asegurará que el complemento de 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 correctamente Certbot snap, ejecute el siguiente comando para habilitar el uso de certbot .
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
Obtenga su Certificado
Cuando ejecute el siguiente comando, certbot lo guiará a través del resto del proceso. Certbot también actualiza su configuración 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.
- Proporcione una dirección de correo electrónico a la que se enviarán los avisos de renovación y seguridad.
- Ingrese y para aceptar los términos del servicio
- Ingrese y o n para aceptar o rechazar compartir su dirección de correo electrónico con los desarrolladores de Certbot
- Confirme los nombres de dominio para los que desea 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@computerfreaks.top - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 (frases que se muestran administradas por Certbot) en el archivo de bloque nginx.
$ 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
}
$
Navegue por su sitio web para confirmar que ahora se muestra el icono de candado.
Proceso de Renovación de Certificado
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. Mientras 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 el certificado Let’s Encrypt SSL en el servidor web NGINX que se ejecuta en Ubuntu 20.04.
En lugar de Cerbot, también puede usar el script ACME 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.