GNU/Linux >> Tutoriales Linux >  >> Panels >> Panels

Cómo proteger Nginx con Let's Encrypt en Ubuntu 20.04

La protección de un sitio web que se ejecuta con Nginx como servidor web se puede hacer con Let's Encrypt, y es por eso que estamos escribiendo este tutorial para usted.

Let's Encrypt es una autoridad de certificación que proporciona certificados TLS/SSL gratuitos válidos por 90 días. SSL significa Secure Sockets Layer y un certificado SSL es un certificado digital que permite la conexión encriptada y la autenticación de la identidad del sitio web. En esta publicación de blog, utilizaremos Certbot para obtener un certificado SSL gratuito para Nginx.

Instalar el certificado SSL gratuito Let's Encrypt en Ubuntu 20.04 con Certbot es un proceso sencillo y debería llevar hasta 10 minutos. ¡Empecemos!

Requisitos

  • Instalación nueva de Ubuntu 20.04
  • Privilegios de usuario:usuario root o no root con privilegios sudo
  • Válido Un registro del dominio dirigido a la dirección IP de su servidor (sudominio.com y www.sudominio.com)

Actualizar el sistema

Antes de comenzar con el proceso de instalación, debemos actualizar el sistema para obtener los últimos paquetes y actualizaciones disponibles.

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

Instalar servidor web Nginx

Para instalar el servidor web Nginx, ejecute los siguientes comandos:

sudo apt install nginx -y

Una vez completada la instalación, habilite e inicie el servicio Nginx:

sudo systemctl enable nginx && sudo systemctl start nginx

Para verificar si todo está bien, verifique el estado del servicio:

sudo systemctl status nginx

Debería recibir el siguiente resultado:

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;

Crear host virtual Nginx

Antes de continuar con la instalación de Free Let's Encrypt, debemos crear un archivo de host virtual que contenga nuestro nombre de dominio. Vaya al directorio de configuración de Nginx y cree el archivo.

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

Pegue las siguientes líneas de código.

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;
        }
}

Compruebe la sintaxis de configuración de Nginx si está bien.

nginx -t

Debería recibir el siguiente resultado:

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 recibe este resultado, puede reiniciar el servicio Nginx y acceder a su sitio web.

sudo systemctl restart nginx

Instalar Certbot

En este momento, nuestro sitio web funciona con el protocolo HTTP. La instalación del certificado SSL gratuito de Let's Encrypt hará que nuestro sitio web se ejecute de forma segura a través del protocolo HTTPS. Antes de comenzar a obtener el certificado, debemos instalar el certbot de Python para Nginx.

sudo apt install certbot python3-certbot-nginx

Una vez que el certbot se haya instalado correctamente, podemos continuar con el paso principal de este tutorial sobre cómo obtener un certificado SSL.

Obtención de un certificado SSL

Para ejecutar el certbot con el complemento Nginx especificando el nombre de su dominio, ejecute el siguiente comando:

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

Después de ejecutar este comando, habrá un par de entradas que deberá completar, como la dirección de correo electrónico, el acuerdo sobre los términos y condiciones, si desea compartir su dirección de correo electrónico o no, y las opciones de redireccionamiento.

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 todo está configurado correctamente, se instalará el certificado y recibirá el siguiente mensaje.

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

Ahora puede acceder a su sitio web de forma segura en https://yourdomain.com

¡Felicidades! Protegió con éxito Nginx con el certificado SSL gratuito Let's Encrypt en su servidor Ubuntu 20.04.

Por supuesto, no tiene que instalar el certificado SSL por su cuenta, y si utiliza uno de nuestros servicios de alojamiento SSD VPS, en cuyo caso simplemente puede solicitar a nuestros administradores de sistemas expertos que lo instalen por usted y aseguren su sitio web. Están disponibles las 24 horas del día, los 7 días de la semana y atenderán su solicitud de inmediato.

Si le gustó esta publicación sobre cómo proteger Nginx con Lets Encrypt en Ubuntu 20.04, compártala con sus amigos en las redes sociales usando los botones a continuación o simplemente deje un comentario en la sección de comentarios. Gracias.


Panels
  1. Asegure Nginx con Let's Encrypt en Ubuntu 18.04 - ¿Cómo hacerlo?

  2. Cómo proteger Nginx con Letsencrypt en Ubuntu 20.04

  3. Cómo instalar Joomla con Nginx en Ubuntu 18.04

  4. Cómo instalar Let's Encrypt en Ubuntu 20.04 con Apache

  5. Cómo instalar Gitea con NGINX y Free Let's Encrypt SSL en Ubuntu 20.04

Cómo proteger Nginx con el certificado SSL de Let's Encrypt

Cómo proteger el servidor LEMP con Let's Encrypt Free SSL en Ubuntu 18.04 VPS

Cómo proteger Apache con Let's Encrypt en CentOS 8

Cómo proteger Nginx con Let's Encrypt en CentOS 8

Cómo proteger Nginx con Let's Encrypt en Ubuntu 20.04

Cómo proteger Apache con Let's Encrypt en Ubuntu 20.04