Serveur Debian

Administration con centré . com !

Serveur Debian

certificate SSL Letsencrypt


sudo apt-get install certbot python3-certbot-nginx                      

sudo systemctl stop nginx
sudo systemctl start nginx

sudo systemctl stop apache2
sudo systemctl start apache2


sudo certbot --apache -d nomdedomaine.fr -d www.nomdedomaine.fr   #Installation automatiquement Apache pour utiliser le certificat.
sudo certbot --nginx -d nomdedomaine.fr -d www.nomdedomaine.fr    #Installation automatiquement Ngnix pour utiliser le certificat.


sudo certbot certificates           #Liste les certificates installé
sudo certbot renew
sudo certbot renew --dry-run        # Tester le renouvellement automatique :
sudo crontab -l                     # Certbot configure automatiquement un cron job pour renouveler les certificats automatiquement

  sudo certbot delete --cert-name nomdedomaine.fr

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



openssl x509 -in /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem -text -noout   #afficher le certificat dans un format plus 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



Install sur Apache

sudo nano /etc/apache2/sites-available/nomdedomaine.fr.conf

sudo a2enmod rewrite
sudo a2enmod ssl

<VirtualHost *:80>
    ServerName nomdedomaine.fr
    ServerAlias www.nomdedomaine.fr
    
    <IfModule mod_ssl.c>
        Redirect permanent / https://nomdedomaine.fr/
    </IfModule>

    <IfModule !mod_ssl.c>
        # Optionnel : afficher une page ou un message si SSL n'est pas disponible
        DocumentRoot /var/www/html
        <Directory /var/www/html>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        ErrorDocument 404 "SSL module not available, unable to redirect."
    </IfModule>
</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

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
</VirtualHost>
</IfModule>

apache2ctl  configtest           
sudo systemctl restart apache2


Install sur Ngnix

sudo nano /etc/nginx/sites-available/nomdedomaine.fr

#Ces commandes sont spécifiques à Apache
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2dismod rewrite
sudo a2dismod ssl

server {
    listen 80;
    server_name nomdedomaine.fr www.nomdedomaine.fr;

    # Redirection vers HTTPS
    location / {
        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;

    location / {
        root /var/www/html;
        index index.html index.htm;
    }

    # Autres configurations de votre site
}

sudo nginx -t
sudo systemctl restart nginx