Apache 2 con conexión segura SSL
La creación de los certificados que utilizo en este apunte se han creado a partir del apunte Crear una Entidad certificadora CA Instalación de paquetes
instalamos openssl:
urano:# apt-get install openssl
Instalamos apache2 con modulo OPENSSL:
urano:# apt-get install apache2 libapache-mod-ssl
Configuración Apache2
habilitamos el modulo ssl en apache:
urano:/etc/apache2# a2enmod ssl Module ssl installed; run /etc/init.d/apache2 force-reload to enable.
Modificamos el puerto del 80 al 443 (seguro) en:
vim /etc/apache2/ports.conf Listen 443
realizamos un reload del server:
urano:/etc/apache2# /etc/init.d/apache2 force-reload Forcing reload of web server: Apache2. urano:/etc/apache2#
comprobación:
urano:/etc/apache2# lsof -nPi COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME dhclient 1708 root 5u IPv4 3660 UDP *:68 sshd 2063 root 3u IPv6 4013 TCP *:22 (LISTEN) sendmail- 2141 root 3u IPv4 4049 TCP 127.0.0.1:25 (LISTEN) sendmail- 2141 root 5u IPv4 4050 TCP 127.0.0.1:587 (LISTEN) ntpd 2155 root 4u IPv4 4075 UDP *:123 ntpd 2155 root 5u IPv6 4076 UDP *:123 ntpd 2155 root 6u IPv4 4077 UDP 127.0.0.1:123 ntpd 2155 root 7u IPv4 4078 UDP 192.168.1.8:123 sshd 2349 root 4u IPv6 4283 TCP 192.168.1.8:22->192.168.1.7:50878 (ESTABLISHED) apache2 2460 root 3u IPv6 4890 TCP *:443 (LISTEN) apache2 2461 www-data 3u IPv6 4890 TCP *:443 (LISTEN) apache2 2462 www-data 3u IPv6 4890 TCP *:443 (LISTEN) apache2 2465 www-data 3u IPv6 4890 TCP *:443 (LISTEN)
creamos un sitio nuevo en /etc/apache2/sites-available/ por ej: prueba (vim prueba) con el contenido:
NameVirtualHost *:443 <VirtualHost *:443> ServerAdmin webmaster@localhost DocumentRoot /var/www/prueba SSLEngine on SSLCertificateFile /etc/apache2/ssl/servidor-cert.pem SSLCertificateKeyFile /etc/apache2/ssl/serv-priv.pem ServerName glue.homeip.net <Directory "/var/www/prueba"> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost>
para habilitar el “virtualhost” hacemos lo siguiente:
a2ensite prueba
Quitar la clave a nuestro certificado
Ya tenemos nuestro virtualhost glue.homeip.net o lo que sea, escuchando en el 443, lo que pasa es que cuando reiniciemos el servidor apache2 nos pedirá la passphrase, quedándose parado.
para solucionar esto realizamos lo siguiente:
nos situamos en:
urano:/etc/apache2/ssl#
hacemos una copia:
urano:/etc/apache2/ssl# cp serv-priv.pem serv-priv.pem.old
le quitamos la clave:
urano:/etc/apache2/ssl# openssl rsa -in serv-priv.pem.old -out server.key Enter pass phrase for serv-priv.pem.old: writing RSA key
modificamos los permisos:
urano:/etc/apache2/ssl# chmod 0400 server.key
borramos la copia:
urano:/etc/apache2/ssl# rm serv-priv.pem.old
realizamosun reload:
urano:/etc/apache2# /etc/init.d/apache2 force-reload
Fallos
En mi caso me sigue pidiendo pass, lo cual indica que necesito modificar el virtualhost, dejándolo de esta manera: (linea comentada y sustituida por otra)
NameVirtualHost *:443 <VirtualHost *:443> ServerAdmin webmaster@localhost DocumentRoot /var/www/prueba SSLEngine on SSLCertificateFile /etc/apache2/ssl/servidor-cert.pem #SSLCertificateKeyFile /etc/apache2/ssl/serv-priv.pem SSLCertificateKeyFile /etc/apache2/ssl/server.key ServerName glue.homeip.net <Directory "/var/www/prueba"> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost>
Final
Ahora todo funciona perfecto, si voy a https://glue.homeip.net me muestra el certificado y tras aceptarlo entro sin problemas.