PROJET AUTOBLOG


EauLand

Archivé

source: EauLand

⇐ retour index

Sécurisé son site avec Apache2 / SSL (Auto-signé)

vendredi 18 juin 2010 à 19:00

Nous allons voir dans cet article comment sécurisé son site avec apache2 via SSL

Pré-requis :

Vous devez bien entendu avoir un LAMP déjà configuré.

Methode 1 que j'avais utilisée sur Ubuntu Jaunty & Ubuntu Hardy

Dans un premier temps ajouter le module ssl :


sudo a2enmod ssl

Ensuite on va éditer le script make-ssl-cert pour mettre la durée que nous voulons :


sudo nano /usr/sbin/make-ssl-cert

Vers la fin du fichier deux lignes nous intéresserons :


if [ "$1" != "generate-default-snakeoil" ]; then
openssl req -config $TMPFILE -new -x509 -nodes -out $output -keyout $output > /dev/null 2>&1

[...]

else
openssl req -config $TMPFILE -new -x509 -nodes \

On va rajouter une durée de 10ans (-days 3650) [par défaut le certificat à une durée de 1mois] :


if [ "$1" != "generate-default-snakeoil" ]; then
openssl req -config $TMPFILE -new -x509 -days 3650 -nodes -out $output -keyout $output > /dev/null 2>&1

[...]

else
openssl req -config $TMPFILE -new -x509 -days 3650 -nodes \

Puis nous pouvons regarder le fichier ssleay.cnf, suivant les distributions son contenu peut être différent


sudo nano /usr/share/ssl-cert/ssleay.cnf

Ici nous avons...


RANDFILE = $ENV::HOME/.rnd

[ req ]
default_bits = 1024
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
prompt = no

[ req_distinguished_name ]
countryName = @CountryName@
stateOrProvinceName = @StateName@
localityName = @LocalityName@
organizationName = @OrganisationName@
organizationalUnitName = @OUName@
commonName = @HostName@
emailAddress = @Email@

... ce que je trouve très bien.

Créons le certificat :


sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/ssl/private/mon_site.pem

 
Maintenant, nous pouvons éditer un hôte virtuel :


sudo nano /etc/apache2/sites-available/mon_site.com

 
Voici un exemple :

NameVirtualHost *:443

<VirtualHost *:443>
     SSLEngine On
     SSLCertificateFile /etc/ssl/private/mon_site.pem
     SSLCertificateKeyFile /etc/ssl/private/mon_site.pem

     ServerAdmin postmaster@mon_site.com
     DocumentRoot /chemin_vers_mon_site/www/

     ServerName mon_site.com

     ScriptAlias /cgi-bin/ "/chemin_vers_mon_site/cgi-bin/"

     CustomLog /var/log/apache2/mon_site_access.log combined
     ErrorLog /var/log/apache2/mon_site_error.log

     <Directory "/chemin_vers_mon_site/www/">
            Options -Indexes Includes FollowSymLinks
            AllowOverride all
            Order allow,deny
            Allow from all
     </Directory>

     <Directory "/chemin_vers_mon_site/cgi-bin/">
            AllowOverride all
            Order allow,deny
            Allow from all
            #Options +ExecCGI
     </Directory>

     ServerSignature Off

</VirtualHost>

Pour finir nous créons un lien :

sudo a2ensite mon_site.com

 

Il reste plus qu'à redémarrer apache :)

 
Methode 2 que j'avais utilisé sur Archlinux

Créons le certificat :


cd /etc/httpd/conf
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

 
Maintenant, nous pouvons éditer un hôte virtuel :

NameVirtualHost *:443

<VirtualHost *:443>
     SSLEngine on
     SSLCertificateFile /etc/httpd/conf/server.crt
     SSLCertificateKeyFile /etc/httpd/conf/server.key

     ServerAdmin postmaster@mon_site.com
     DocumentRoot /chemin_vers_mon_site/www/

     ServerName mon_site.com

     ScriptAlias /cgi-bin/ "/chemin_vers_mon_site/cgi-bin/"

     CustomLog /var/log/httpd/mon_site_access.log combined
     ErrorLog /var/log/httpd/mon_site_error.log

     <Directory "/chemin_vers_mon_site/www/">
         Options -Indexes Includes FollowSymLinks
         AllowOverride all
         Order allow,deny
         Allow from all
     </Directory>

     <Directory "/chemin_vers_mon_site/cgi-bin/">
         AllowOverride all
         Order allow,deny
         Allow from all
         Options +ExecCGI
     </Directory>

     ServerSignature Off

</VirtualHost>

 

Il reste plus qu'à redémarrer apache :)

 


Sources:

Creating a self signed SSL certificate for apache2 on Debian Lenny
Sécuriser Apache2 avec SSL
Serveur Web Apache - SSL - PHP
How to create a self-signed SSL Certificate