Activation https pour apache2

17 avril 2020

La procédure qui suit est extraite du site suivant :
https://doc.ubuntu-fr.org/tutoriel/securiser_apache2_avec_ssl
Ce qui suit fonctionne pour UBUNTU 18.04 LTS

Sur une installation standard d’apache2, avant de lancer ce qui suit, il faut installer le greffon suivant si celui-ci n’est pas encore installé :
apt install python-certbot-apache

La séquence suivante a fonctionné sans anicroches.
Tout d’abord il faut permettre en place la vitualisation des sites.
Dans l’exemple qui suit on veut ajouter au serveur le site cech.fr
Celui-ci sera dans le répertoire /var/www/site-cech
Pour valider le bon fonctionnement y copier le fichier index.html
que l’installation d’apache a créé.
Attention à la gestion des droits d’accès, de propriété et groupe.
Le plus simple est de reproduire ceux de /var/www/html
Dans ce qui suit la séquence cech.fr est à remplacer par le domaine choisi.
Créer dans le répertoire /etc/apache2/sites-available
créer le fichier de redirection site-cech.conf

Les mots en gras italique sont à adapter.


<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.cech.fr
ServerAlias cech.fr
ServerAdmin webmaster@localhost
DocumentRoot /var/www/site-cech
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>


 

# Activation https pour apache
a2enmod ssl # activation mode ssl
systemctl reload apache2 # relancer apache2
apache2ctl -M | grep ssl # vérification ssl
# greffon à installer si cerbot –apache provoque une erreur
# voir plus haut
apt install python-certbot-apache # installation greffon apache
# installation du créateur de certificats
apt install software-properties-common
add-apt-repository ppa:certbot/certbot
apt update
apt install certbot
##################################### Reste à créer le certificat
certbot –apache # création du certificat ssl / copie d’écran disponible plus bas.
##################################### Vérifier que le site passe le ssl
https://www.sslshopper.com/ssl-checker.html
################################################################
# Sans relancer apache2 le site devrait fonctionner en https://
################################################################


Copie de l’écran d’installation du certificat ssl
Les données entrées au clavier sont en GRAS

root@my-server:/etc/apache2# certbot –apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter ‘c’ to
cancel): (email de l’admin du site)

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
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

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
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
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated) (Enter ‘c’ to cancel): (le nom de domaine)
Obtaining a new certificate
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.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
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Congratulations! You have successfully enabled https://achc.site
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=achc.site
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

IMPORTANT NOTES:
– Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/(le nom de domaine)/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/achc.site/privkey.pem
Your cert will expire on 2020-07-16. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the « certonly » option. To non-interactively renew *all* of
your certificates, run « certbot renew »
– 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

root@my-server:/etc/apache2#


Cette procédure possède l’inconvénient suivant : le certificat n’est valable que soixante jours.


Fichier généré par le script certbot -apache
Voir les modifications et les comparer au fichier initial.


Remarque importante

La paire de clefs ssl générée permet de protéger un nom de domaine. Si l’on protège
https://www.mon-site.fr ce jeu de clés ne protégera pas https://mon-site.fr

()