Prérequis
- Un serveur Ubuntu/Debian ou AlmaLinux 9/Rocky Linux 9
- Un nom de domaine pointant vers votre serveur
- Nginx ou Apache installé
- Port 80 ouvert
Let's Encrypt fournit des certificats SSL gratuits et automatisés. Certbot est l'outil officiel pour obtenir et renouveler ces certificats.
1. Installer Certbot
apt update
apt install -y certbot
# Plugin pour Nginx
apt install -y python3-certbot-nginx
# Ou plugin pour Apache
apt install -y python3-certbot-apache# Installer EPEL (requis pour Certbot)
dnf install -y epel-release
# Installer Certbot
dnf install -y certbot
# Plugin pour Nginx
dnf install -y python3-certbot-nginx
# Ou plugin pour Apache
dnf install -y python3-certbot-apache2. Obtenir un certificat avec Nginx
# Certbot configure automatiquement Nginx
certbot --nginx -d votredomaine.com -d www.votredomaine.com
# Suivez les instructions :
# - Entrez votre email
# - Acceptez les conditions
# - Choisissez si vous voulez rediriger HTTP vers HTTPS (recommandé)3. Obtenir un certificat avec Apache
certbot --apache -d votredomaine.com -d www.votredomaine.com4. Mode standalone (sans serveur web)
# Arrêtez temporairement votre serveur web
systemctl stop nginx # ou apache2
# Obtenir le certificat
certbot certonly --standalone -d votredomaine.com -d www.votredomaine.com
# Redémarrer le serveur web
systemctl start nginx5. Mode webroot (sans redémarrage)
# Si votre serveur web tourne déjà
certbot certonly --webroot -w /var/www/html -d votredomaine.com -d www.votredomaine.com6. Emplacement des certificats
# Les certificats sont dans /etc/letsencrypt/live/votredomaine.com/
ls -la /etc/letsencrypt/live/votredomaine.com/
# Fichiers :
# - privkey.pem : Clé privée
# - fullchain.pem : Certificat + chaîne complète (à utiliser)
# - cert.pem : Certificat seul
# - chain.pem : Chaîne intermédiaire7. Configuration Nginx manuelle
server {
listen 80;
server_name votredomaine.com www.votredomaine.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name votredomaine.com www.votredomaine.com;
# Certificats Let's Encrypt
ssl_certificate /etc/letsencrypt/live/votredomaine.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/votredomaine.com/privkey.pem;
# Paramètres SSL recommandés
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
# HSTS (optionnel mais recommandé)
add_header Strict-Transport-Security "max-age=63072000" always;
root /var/www/votredomaine.com;
index index.html index.php;
# ... reste de la configuration
}8. Renouvellement automatique
Certbot configure automatiquement le renouvellement via un timer systemd ou cron.
# Tester le renouvellement (simulation)
certbot renew --dry-run
# Voir le timer systemd
systemctl list-timers | grep certbot
# Ou voir le cron
cat /etc/cron.d/certbot
# Forcer le renouvellement
certbot renew9. Certificat wildcard (*.domaine.com)
# Les wildcards nécessitent une validation DNS
certbot certonly --manual --preferred-challenges dns -d "*.votredomaine.com" -d votredomaine.com
# Certbot vous demandera de créer un enregistrement DNS TXT
# _acme-challenge.votredomaine.com avec une valeur spécifique
# Pour automatiser avec Cloudflare :
apt install -y python3-certbot-dns-cloudflare
# Créer le fichier de credentials
cat > /etc/letsencrypt/cloudflare.ini << 'EOF'
dns_cloudflare_api_token = votre_token_api_cloudflare
EOF
chmod 600 /etc/letsencrypt/cloudflare.ini
# Obtenir le certificat
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d "*.votredomaine.com" -d votredomaine.com# Les wildcards nécessitent une validation DNS
certbot certonly --manual --preferred-challenges dns -d "*.votredomaine.com" -d votredomaine.com
# Pour automatiser avec Cloudflare :
dnf install -y python3-certbot-dns-cloudflare
# Créer le fichier de credentials
cat > /etc/letsencrypt/cloudflare.ini << 'EOF'
dns_cloudflare_api_token = votre_token_api_cloudflare
EOF
chmod 600 /etc/letsencrypt/cloudflare.ini
# Obtenir le certificat
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d "*.votredomaine.com" -d votredomaine.com10. Commandes utiles
# Lister les certificats
certbot certificates
# Supprimer un certificat
certbot delete --cert-name votredomaine.com
# Ajouter un domaine à un certificat existant
certbot certonly --expand -d votredomaine.com -d www.votredomaine.com -d nouveau.votredomaine.com
# Révoquer un certificat
certbot revoke --cert-path /etc/letsencrypt/live/votredomaine.com/cert.pem11. Hook de renouvellement
# Créer un script qui s'exécute après le renouvellement
cat > /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh << 'EOF'
#!/bin/bash
systemctl reload nginx
EOF
chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.shVérifier la configuration SSL
Testez votre configuration SSL :
- SSL Labs : ssllabs.com/ssltest
- SSL Checker : sslshopper.com/ssl-checker.html
- Security Headers : securityheaders.com
SSL activé !
Votre site est maintenant sécurisé avec HTTPS. Le certificat se renouvellera automatiquement avant expiration.