Certificat SSL avec Let's Encrypt (certbot)
# Pour Apache :
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d wsbridge.rl456.best -d www.wsbridge.rl456.best
# Pour Nginx :
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d nomdedomaine.fr -d www.nomdedomaine.fr
sudo certbot --apache -d nomdedomaine.fr -d www.nomdedomaine.fr # Configure automatiquement Apache pour utiliser le certificat
sudo certbot --nginx -d nomdedomaine.fr -d www.nomdedomaine.fr # Configure automatiquement Nginx pour utiliser le certificat
sudo certbot --apache --redirect -d wsbridge.rl456.best -d www.wsbridge.rl456.best
sudo systemctl restart nginx
sudo systemctl restart apache2
sudo certbot certificates # Liste les certificats installés
sudo certbot renew
sudo certbot renew --dry-run # Tester le renouvellement automatique
systemctl list-timers | grep certbot
sudo certbot delete --cert-name nomdedomaine.fr
Exemple de résultat de certbot certificates :
Found the following certs:
Certificate Name: nomdedomaine.fr
Serial Number: 3ecfd85783d389885b59723XXXXXXXXXXXXXX
Key Type: RSA
Domains: nomdedomaine.fr www.nomdedomaine.fr
Expiry Date: 2024-01-01 00:00:01+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem
Private Key Path: /etc/letsencrypt/live/nomdedomaine.fr/privkey.pem
Vérifier un certificat avec OpenSSL :
openssl x509 -in /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem -text -noout # Afficher le certificat dans un format lisible
openssl x509 -in /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem -enddate -noout # Vérifier la date d'expiration
openssl x509 -in /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem -issuer -noout # Afficher l'autorité émettrice
Installation sur Apache
<VirtualHost *:80>
ServerName nomdedomaine.fr
ServerAlias www.nomdedomaine.fr
Redirect permanent / https://nomdedomaine.fr/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@nomdedomaine.fr
ServerName nomdedomaine.fr
ServerAlias www.nomdedomaine.fr
DocumentRoot /var/www/nomdedomaine.fr
<Directory /var/www/nomdedomaine.fr>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/nomdedomaine.fr-error.log
CustomLog ${APACHE_LOG_DIR}/nomdedomaine.fr-access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/nomdedomaine.fr/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
sudo a2enmod rewrite ssl
sudo apache2ctl configtest
sudo systemctl restart apache2
Installation sur Nginx
server {
listen 80;
server_name nomdedomaine.fr www.nomdedomaine.fr;
# Redirection vers HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name nomdedomaine.fr www.nomdedomaine.fr;
ssl_certificate /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nomdedomaine.fr/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
# Autres configurations de votre site
}
sudo nginx -t
sudo systemctl restart nginx