- Detalles
- Escrito por Super User
- Categoría: Servidores
- Publicado: 03 Abril 2014
- Visto: 6111
En este ejemplo vamos a utilizar una maquina con Debian 6.
Si ya tienes instalado Apache perfecto, si nó con un simple comando se instala:
apt-get install apache2
Una vez instalado Apache nos quedan 3 cosas para que funcione con SSL:
- Generar o importar un certivicado.
- Habilitar Apache SSL.
- Configurar las opciones de SSL.
Generar un certificado
Generar un certificado desde cero nos sirve para proteger el tráfico intercambiado entre los clientes y el servidor, sin embargo, al estar firmado por una autoridad certificadora (en nuestra propia máquina) en la que no se confía por lo que generará advertencias a los usuarios.
En un entorno de producción se importaría un certificado de pago (Verisign, Comodo, etc...) y "de confianza" para evitar este problema.
Instalamos el paquete que luego generará nuestro certificado SSL
apt-get install openssl
Vamos a generar nuestro certificado SSL para Apache2 con un único comando:
openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.pem
Esta es la salida que nos da:
Generating a 1024 bit RSA private key
............................++++++
....++++++
writing new private key to '/etc/apache2/apache.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:es
State or Province Name (full name) [Some-State]:estado
Locality Name (eg, city) []:aqui
Organization Name (eg, company) [Internet Widgits Pty Ltd]:empresa
Organizational Unit Name (eg, section) []:unidad
Common Name (eg, YOUR name) []:pepito
Email Address []:Esta dirección de correo electrónico está siendo protegida contra los robots de spam. Necesita tener JavaScript habilitado para poder verlo.
Lo primero que hace este comando es generar una clave privada RSA, que guarda en nuestro archivo .pem, y luego nos hace una serie de preguntas sobre nuestros datos, información que luego irá añadida en el certificado.
Habilitar soporte SSL
Para utilizar SSL en Apache2 se debe de habilitar el módulo mod_ssl, esto se puede lograr utilizando la herramienta a2enmod:
root@xx:~# a2enmod ssl
Enabling module ssl.
See /usr/share/doc/apache2.2-common/README.Debian.gz on how to configure SSL and create self-signed certificates.
Run '/etc/init.d/apache2 restart' to activate new configuration!
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
Utiliza este comando para ver el tuyo:
more /etc/apache2/ports.conf
Configurando tus Hosts SSL
Solo nos falta configurar los virtual hosts para que se cargue la configuración SSL. Para ello introducimos el comando:
a2ensite default-ssl
Editamos el archivo default-ssl con este comando:
nano /etc/apache2/sites-enabled/default-ssl
Y sustituimos estas dos líneas:
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
Por esta:
SSLCertificateFile /etc/apache2/apache.pem
Reiniciamos el servicio:
/etc/init.d/apache2 restart
Y listo !!!
Podemos comprobarlo con: https://ip-servidor
En un próximo artículo veremos como forzar a que todas las peticiones al Apache vayan por SSL.