GNU/Linux >> Tutoriales Linux >  >> Cent OS

Cómo configurar el certificado Let's Encrypt SSL con Nginx en CentOS 8 / RHEL 8 y CentOS 7 / RHEL 7

Let's Encrypt es una autoridad de certificación que proporciona certificados SSL gratuitos para que los sitios web habiliten el cifrado TLS. Fue lanzado en abril de 2016.

Let's Encrypt automatiza el proceso de creación, validación, firma, implementación y renovación de certificados para sitios web seguros.

Actualmente, Let's encrypt admite la emisión de certificación automatizada para Apache, Nginx, Plex y Haproxy.

Requisitos

Debe tener una pila LEMP configurada en su sistema RHEL/CentOS.

LEER :Cómo instalar LEMP Stack en CentOS 8 / RHEL 8

LEER: Cómo instalar LEMP Stack en CentOS 7/RHEL 7

Instalar Certbot

Para generar un certificado de Let's Encrypt para su dominio, debe tener acceso a la terminal y el cliente Certbot ACME instalado en su sistema. Maneja la emisión de certificados y actualiza la configuración de Nginx para usar el certificado creado sin tiempo de inactividad.

Certbot está disponible en el repositorio EPEL solo para CentOS 7/RHEL 7. Por lo tanto, debemos descargar el instalador de Certbot manualmente para CentOS 8/RHEL 8 desde su sitio oficial.

### CentOS 8 / RHEL 8 ###

curl -O https://dl.eff.org/certbot-auto

mv certbot-auto /usr/local/bin/certbot-auto

chmod 0755 /usr/local/bin/certbot-auto

### CentOS 7 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install -y certbot python2-certbot-nginx

### RHEL 7 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

subscription-manager repos --enable rhel-7-server-optional-rpms

yum install -y certbot python2-certbot-nginx

Crear servidor virtual

Ahora crearemos un archivo de configuración de host virtual (bloque de servidor) para el dominio www.itzgeek.net.

Este bloque de servidor sirve la versión HTTP de su dominio.
vi /etc/nginx/conf.d/www.itzgeek.net.conf

Utilice la siguiente información.

server {
   server_name www.itzgeek.net;
   root /opt/nginx/www.itzgeek.net;

   location / {
       index index.html index.htm index.php;
   }

   access_log /var/log/nginx/www.itzgeek.net.access.log;
   error_log /var/log/nginx/www.itzgeek.net.error.log;

   location ~ \.php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   }
}

Cree una raíz de documento para colocar sus archivos HTML.

mkdir -p /opt/nginx/www.itzgeek.net

Cambia el permiso del directorio.

chown -R nginx:nginx /opt/nginx/www.itzgeek.net

Coloque el archivo HTML de prueba en la raíz del documento de su dominio web.

echo "This is a test site @ www.itzgeek.net" > /opt/nginx/www.itzgeek.net/index.html

Reinicie el servicio Nginx.

systemctl restart nginx

Crear/Actualizar Registro DNS

Acceda a su herramienta de administración de DNS o registrador de dominios y cree un registro A/CNAME para el dominio. Ej:www.itzgeek.net.

Espere un tiempo para permitir que el registro se propague.

Compruebe la propagación de DNS con la utilidad Nslookup yum install -y bind-utils.

Instalar certificado Let's Encrypt

Use el comando certbot para crear e instalar el certificado Let's Encrypt.

### CentOS 8 / RHEL 8 ###

/usr/local/bin/certbot-auto --nginx

### CentOS 7 / RHEL 7 ###

certbot --nginx

Siga las indicaciones interactivas y genere e instale el certificado.

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]  << Email Address to receive renewal/security notification

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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  << Access Terms and Conditions

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: Y  << Subscribe to Newsletter

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1  << Choose domain name to generate certificate
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/www.itzgeek.net.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  << Redirect traffic from HTTP to HTTPS
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/www.itzgeek.net.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.itzgeek.net

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/privkey.pem
   Your cert will expire on 2019-11-02. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto 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

Redirigir solicitudes HTTP que no sean www a www HTTPS con Nginx (opcional)

Ahora configuraremos el servidor Nginx para redirigir el tráfico que proviene del sitio HTTP que no es www al sitio WW HTTPS, es decir, http://itzgeek.net>> https://www.itzgeek.net .

Aquí, usaremos el mismo archivo de configuración que creamos para la versión HTTP del sitio para realizar la redirección del sitio HTTP que no es www a WW HTTPS.

vi /etc/nginx/conf.d/www.itzgeek.net.conf

Agregue la siguiente información al final del archivo.

# Redirect NON-WWW HTTP to WWW HTTPS

server {
    if ($host = itzgeek.net) {
        return 301 https://www.itzgeek.net$request_uri;
    }


   server_name itzgeek.net;
    listen 80;
    return 404;

}

Reinicie el servicio Nginx.

systemctl restart nginx

Cortafuegos

Configure el cortafuegos para permitir solicitudes HTTPS.

firewall-cmd --permanent --add-port=443/tcp

firewall-cmd --reload

Verificar el certificado Let's Encrypt

Verifique los detalles del certificado Let's Encrypt yendo a la versión HTTPS de su sitio web.

http://tu-http-sitio-web

O

https://tu-https-sitio-web

Certificado SSL de prueba

Verifique su certificado SSL por cualquier problema y sus clasificaciones de seguridad yendo a la siguiente URL.

https://www.ssllabs.com/ssltest/analyze.html?d=www.itzgeek.net

Renovar el certificado de Let's Encrypt

El certificado de Let's Encrypt viene con una validez de 90 días y debe renovarse antes de que caduque.

De forma predeterminada, tanto CentOS 7 como RHEL 7 están configurados con una entrada del programador cron que se ejecuta dos veces al día para renovar el certificado de Let's Encrypt.

Desafortunadamente, para CentOS 8/RHEL 8, necesitamos configurar el programador cron manualmente.

echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && /usr/local/bin/certbot-auto renew" | sudo tee -a /etc/crontab > /dev/null

También puede simular el proceso de renovación del certificado con el siguiente comando para asegurarse de que la renovación se realice sin problemas.

### CentOS 8 / RHEL 8 ###

/usr/local/bin/certbot-auto renew --dry-run

### CentOS 7 / RHEL 7 ###

certbot renew --dry-run

Salida:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/www.itzgeek.net.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - 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.

Si el resultado no informa ningún problema, la renovación del certificado funcionará como se esperaba.

Conclusión

Eso es todo. Espero que haya aprendido a configurar el certificado Let's Encrypt SSL con Nginx en CentOS 8/RHEL 8 y CentOS 7/RHEL 7. Comparta sus comentarios en la sección de comentarios.


Cent OS
  1. Cómo instalar ssl en RHEL 8 / CentOS 8

  2. Asegure Nginx con Lets Encrypt en CentOS 7

  3. Instalar WordPress con Nginx en CentOS 7 / RHEL 7

  4. Cómo instalar phpMyAdmin con Nginx en CentOS 7 / RHEL 7

  5. Cómo instalar Let's Encrypt en CentOS 8 con Nginx

Cómo instalar Let's Encrypt SSL con Nginx en CentOS 7

Cómo instalar Let's Encrypt SSL con Apache en CentOS 7

Cómo instalar Let's Encrypt SSL con Lighttpd en CentOS 7

Cómo instalar Nginx con Let's Encrypt SSL en Fedora 35

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

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