Cómo instalar un certificado SSL en un servidor web Apache

En la era digital actual, la seguridad en línea es más importante que nunca. Con el aumento constante de las amenazas cibernéticas y la creciente preocupación por la privacidad de los datos, asegurar la comunicación entre los servidores web y los navegadores se ha convertido en una prioridad.

Específicamente, para los sitios web que se ejecutan en servidores Apache, la implementación de un certificado SSL no solo mejora la seguridad, sino que también fomenta una mayor confianza entre los usuarios.

En este tutorial veremos los requisitos previos y el procedimiento que debes llevar a cabo si quieres instalar un certificado SSL en un servidor web Apache.

Requisitos previos para la instalación del certificado SSL en Apache

Antes de avanzar en esta guía, necesitarás:

  • Acceso al SSH root (raíz) de CentOS VPS
  • El servidor web Apache con dominio y vhost correctamente configurado.

Instalar certificado SSL en Apache

Para instalar este certificado debemos utilizar una empresa que nos permita instalar el certificado SSL de manera confiable. Let’s Encrypt es un pionero en implementación SSL gratuita y puede ser usado como certificación de proveedor en algunos casos.

Paso 1: instalar los módulos dependientes

Para instalar cerbot tendrás que instalar el repertorio EPEL que no está disponible por default, mod_ssl también es requerido para que la encriptación sea reconocida por Apache.

Para instalar ambas dependencias tienes que ejecutar el comando:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yum install epel-release mod_ssl
yum install epel-release mod_ssl
yum install epel-release mod_ssl

Ahora deberías de poder proceder con la instalación de cerbot.

Paso 2: descargar el cliente Let’s Encrypt

Ahora tienes que instalar el cliente cerbot del repositorio EPEL:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yum install python-certbot-apache
yum install python-certbot-apache
yum install python-certbot-apache

Cerbot ahora debería de estar instalado y disponible para su uso.

Paso 3: instalar y configurar el certificado SSL en Apache

Cerbot manejará la administración del certificado SSL de una forma muy sencilla, generarando un nuevo certificado para el dominio como un parámetro.

En este caso, ejemplo.com será usado como el dominio que se certificará:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
certbot --apache -d ejemplo.com
certbot --apache -d ejemplo.com
certbot --apache -d ejemplo.com

Si quieres generar múltiples dominios o subdominios SSL, tienes que ejecutar este comando:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
certbot --apache -d ejemplo.com -d www.ejemplo.com
certbot --apache -d ejemplo.com -d www.ejemplo.com
certbot --apache -d ejemplo.com -d www.ejemplo.com

¡Importante! El primer dominio debe de ser tu dominio base. En este caso es ejemplo.com.

Mientras se instala el certificado te encontraras con una guía paso-a-paso en la que podrás personalizar algunos detalles del certificado. Tendrás la opción de elegir entre forzar el HTTPS o dejar HTTP como el protocolo por default, se solicitará proporcionar un correo electrónico por propósitos de seguridad.

Una vez que hayas terminado la instalación verás un mensaje similar a este:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
IMPORTANT NOTES:
- If you lose your account credentials, you can recover through
e-mails sent to user@example.com.
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/example.com/fullchain.pem. Your cert
will expire on 2016-04-21. To obtain a new version of the
certificate in the future, simply run Let's Encrypt again.
- Your account credentials have been saved in your Let's Encrypt
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 Let's
Encrypt so making regular backups of this folder is ideal.
- If you like Let's Encrypt, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
IMPORTANT NOTES: - If you lose your account credentials, you can recover through e-mails sent to user@example.com. - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem. Your cert will expire on 2016-04-21. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - Your account credentials have been saved in your Let's Encrypt 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 Let's Encrypt so making regular backups of this folder is ideal. - If you like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
IMPORTANT NOTES:

- If you lose your account credentials, you can recover through

e-mails sent to user@example.com.

- Congratulations! Your certificate and chain have been saved at

/etc/letsencrypt/live/example.com/fullchain.pem. Your cert

will expire on 2016-04-21. To obtain a new version of the

certificate in the future, simply run Let's Encrypt again.

- Your account credentials have been saved in your Let's Encrypt

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 Let's

Encrypt so making regular backups of this folder is ideal.

- If you like Let's Encrypt, please consider supporting our work by:

Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate

Donating to EFF:                    https://eff.org/donate-le

Paso 4: establecer la renovación automática del certificado

La certificación de Let’s Encrypt es válida por 90 días. Sin embargo, se recomienda renovarlo cada 60 días para evitar cualquier problema. Para hacer esto, cerbot no ayudara con el comando renew, tan solo revisará si al certificado le quedan menos de 30 días para expirar.

Para esto tienes que ejecutar el siguiente comando:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
certbot renew
certbot renew
certbot renew

Si la instalación del certificado es reciente, entonces cerbot solo revisará la fecha de expiración:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Processing /etc/letsencrypt/renewal/example.com.conf
The following certs are not due for renewal yet:
/etc/letsencrypt/live/example.com/fullchain.pem (skipped)
No renewals were attempted.
Processing /etc/letsencrypt/renewal/example.com.conf The following certs are not due for renewal yet: /etc/letsencrypt/live/example.com/fullchain.pem (skipped) No renewals were attempted.
Processing /etc/letsencrypt/renewal/example.com.conf

The following certs are not due for renewal yet:

/etc/letsencrypt/live/example.com/fullchain.pem (skipped)

No renewals were attempted.

Para ejecutar automáticamente el proceso de renovación tienes que establecer un cronjob, ejecutando el siguiente comando para ejecutar el crontab:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
crontab -e
crontab -e
crontab -e

Este trabajo se puede programar para que corra todos los lunes a media noche:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
0 0 * * 1 /usr/bin/certbot renew >> /var/log/sslrenew.log
0 0 * * 1 /usr/bin/certbot renew >> /var/log/sslrenew.log
0 0 * * 1 /usr/bin/certbot renew >> /var/log/sslrenew.log

La salida del script será enviada al archivo /var/log/sslrenew.log.

Conclusión

Una vez que hayas terminado, todo el tráfico entre el servidor y el cliente será encriptado. Esto se ha convertido en un estándar para la seguridad de los sitios, especialmente aquellos de comercio electrónico.

De esta manera has asegurado tu servidor web Apache al implementar la mejor herramienta de seguridad: un certificado SSL gratis. Si tienes dudas o preguntas, escríbelas en la sección de abajo. ¡Buena suerte!

Author
El autor

Gustavo B.

Gustavo es un apasionado por la creación de sitios web. Se enfoca en la aplicación de estrategias SEO en Hostinger para España y Latinoamérica, así como la creación de contenidos de alto nivel. Cuando no está aplicando nuevos trucos en WordPress lo puedes encontrar tocando la guitarra, viajando o tomando un curso online.