Souhaitez-vous savoir comment sécuriser votre site Web Apache en utilisant le certificat HTTP Encryptage gratuit? Dans ce tutoriel, nous allons vous montrer toutes les étapes nécessaires pour sécuriser Apache avec Let's Encrypt sur Ubuntu Linux.

• Version Ubuntu: 18.04.

Pour illustrer l'installation, nous allons utiliser l'un de nos domaines nommé MINING-POOL.NINJA.

Vous devrez modifier les fichiers de configuration et remplacer notre nom de domaine MINING-POOL.NINJA par votre nom de domaine.

Liste du Matériel:

La section suivante présente la liste du matériel utilisé pour créer ce didacticiel WordPress.

Tous les éléments matériels répertoriés ci-dessus sont disponibles sur le site Web d'Amazon.

Tutoriel Relatif à Apache:

Sur cette page, nous offrons un accès rapide à une liste de tutoriels liés à Apache.

1. Achetez un Nom de Domaine

Tout d'abord, vous devez accéder à la GODADDY et créer un compte.

Ce compte sera utilisé pour acheter un domaine DNS.

Dans notre exemple, nous achetons le domaine nommé MINING-POOL.NINJA.

N'hésitez pas à utiliser n'importe quel site Web pour acheter un domaine DNS.

GoDaddy est juste mon choix préféré.

2. Configurez une entrée DNS

Maintenant, vous devez configurer un registre DNS pointant sur votre serveur Web Apache.

Après avoir acheté un domaine DNS, vous devez créer une entrée DNS pointant l'adresse de votre site Web vers l'ordinateur exécutant Ubuntu Linux.

Dans notre exemple, nous avons créé une entrée DNS pointant le domaine MINING-POOL.NINJA vers l'adresse IP 35.163.100.49.

HTTPS DNS Entry

Utilisez les commandes suivantes pour tester votre configuration DNS sur un ordinateur exécutant Linux.

# apt-get update
# apt-get install dnsutils
# nslookup mining-pool.ninja

Non-authoritative answer:
Name: mining-pool.ninja
Address: 35.163.100.49

La commande ci-dessus a confirmé que le domaine pointe vers l'adresse IP 35.163.100.49.

3. Installer le Serveur Web Apache

L'autorité de certification Let's Encrypt requiert que l'utilisateur dispose d'un serveur Web Apache entièrement fonctionnel.

Nous devons installer le serveur Web Apache et tous les logiciels requis.

Sur la console Linux, utilisez les commandes suivantes pour installer les packages requis.

# apt-get update
# apt-get install apache2 php7.2 php7.2-mysql libapache2-mod-php7.2
# apt-get install openssl

Activez Apache mod_rewrite et modifiez le fichier apache2.conf.

# a2enmod rewrite
# vi /etc/apache2/apache2.conf

A la fin du fichier, ajoutez les lignes suivantes.

<Directory /var/www/html>
AllowOverride All
</Directory>

Créez un fichier de configuration Apache Virtualhost sur votre site Web.

# vi /etc/apache2/sites-available/mining-pool.conf

Gardez à l'esprit que le nom et l'emplacement de votre fichier Virtualhost peuvent différer de ceux du mien.

A titre d'exemple, voici le contenu de notre fichier:

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error
</VirtualHost>

Créez la liste des dossiers requis.

Définissez l'autorisation de fichier correcte sur tous les dossiers.

N'oubliez pas que l'emplacement de votre dossier peut ne pas être le même que le mien.

# mkdir /websites
# cd /websites
# mkdir www logs
# chown www-data.www-data /websites -R

Activez votre configuration Apache Virtualhost et redémarrez le service Apache.

# a2ensite mining-pool.conf
# systemctl reload apache2

4. Configurez le Certificat HTTPS Gratuit sur Apache

Sur la console Linux, utilisez la commande suivante pour installer les packages requis.

# apt-get install software-properties-common
# add-apt-repository universe
# add-apt-repository ppa:certbot/certbot
# apt-get update
# apt-get install python-certbot-apache

Le script Certbot nécessite que l'utilisateur dispose d'un serveur Web Apache entièrement fonctionnel.

Nous avons déjà terminé notre installation et configuration Apache Virtualhost.

Utilisez la demande de commande suivante et installez le certificat HTTPS gratuit Apache.

N'oubliez pas que votre nom de domaine ne doit pas être identique au mien.

# certbot --apache -d mining-pool.ninja

• Appuyez sur (A) pour accepter les conditions d'utilisation.
• Appuyez sur (Y) pour partager votre courrier électronique et recevoir des lettres d’information.
• Appuyez sur (2) pour rediriger automatiquement votre site Web HTTP vers les versions HTTPS.

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): techexpert.tips@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mining-pool.ninja
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/mining-pool-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/mining-pool.conf to ssl vhost in /etc/apache2/sites-available/mining-pool-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://mining-pool.ninja

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=mining-pool.ninja
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Your cert will expire on 2019-03-19. 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

Le système demande automatiquement le certificat et configure votre serveur Web Apache pour qu'il redirige tous les accès HTTP vers la version HTTPS de votre site Web.

Dans notre exemple, le système a créé un fichier de configuration HTTPS Virtualhost nommé mining-pool-le-ssl.conf.

Voici le contenu du fichier de configuration HTTPS Virtualhost mining-pool-le-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error

SSLCertificateFile /etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Le fichier KEY contient votre clé privée de certificat et doit être gardé dans un endroit sûr tout le temps.

Voici le contenu du fichier KEY: /etc/letsencrypt/live/mining-pool.ninja/privkey.pem

-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwGYFx4kcQmYC5
gJftnjZhWNVZkIL7wSMTFtFfIY37PNbVNeJ11HoudX8HWout8qXOxBvHE8oU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jA8XH7FFbFeJ/X2hjjY9Zvm8xGMO9cwy
/TM4tL9uo/W77r/jsPXXdRPARD98Z1xk3l1NMvaxZURtU/NN0On5iUABQQKBgGIu
FiER0R3iAF68WLAT7TVx4UgK2nsdO2eQCXkJDhpAyPEIjK8RWu/10oaS4k4guXYW
IYut3+dZpCFAVVCMwvaSlSMZbkk4464VBM3zxgRvxyoW1DXuO2ihWiD/fNZ8opTf
l7EcqR2fjOFKhgUF7qaZYG4GDYxHVuNhSkzDsdvHAoGBAIfDk7fLsG/BYROxJpzN
b1CoG8DE+DKYTWwMWW45rDF0ImbC6H3fg876CeZ3YKGWqt9qkha7gnGGVRRufP15
O7ZEXebZXeDYafXSNcnqSe7FSNtVr1eFlTWmL8OiWQuaqxjs/VogdWfhkEGPISVF
AOM3I6XSGx4NxW2RgYmvQZ4O
-----END PRIVATE KEY-----

Le système a automatiquement modifié votre fichier de configuration Apache Virtualhost d'origine pour rediriger toutes les requêtes HTTP vers la version HTTPS.

Voici le contenu du fichier de configuration HTTP Virtualhost d'origine mis à jour, mining-pool.conf:

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error
RewriteEngine on
RewriteCond %{SERVER_NAME} =mining-pool.ninja
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>

5. Testez votre site web Apache HTTPS

Pour tester votre installation, ouvrez votre navigateur et entrez l'adresse HTTP de votre site Web.

Dans notre exemple, l'URL suivante a été entrée dans le navigateur:

• http://mining-pool.ninja

Au lieu de la version HTTP, la version HTTPS de votre site Web devrait être présentée.

Lets Encrypt Apache

Félicitations, votre configuration Apache utilise maintenant le certificat HTTPS gratuit de LET'S ENCRYPT.

6. Renouveler le certificat Apache HTTPS

Vous devez savoir que les certificats de Let's Encrypt ne sont valides que pendant quatre vingt dix jours.

Apache HTTPS Free Certificate

Le système crée une tâche planifiée pour renouveler automatiquement tout certificat dans les trente jours suivant l'expiration.

Le nom de la tâche planifiée est certbot et il se trouve dans le répertoire /etc/cron.d.

Voici le contenu du fichier /etc/cron.d/certbot:

# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
#
# Important Note! This cronjob will NOT be executed if you are
# running systemd as your init system. If you are running systemd,
# the cronjob.timer function takes precedence over this cronjob. For
# more details, see the systemd.timer manpage, or use systemctl show
# certbot.timer.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

Utilisez la commande suivante pour simuler le processus de renouvellement du certificat.

# certbot renew --dry-run

Si tout fonctionne, vous devriez voir les messages suivants:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mining-pool.ninja.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for mining-pool.ninja
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.