informatique:serveur:web-linux-apache:https_www_apache2

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
informatique:serveur:web-linux-apache:https_www_apache2 [2023/02/09 17:12] – supprimée - modification externe (Unknown date) informatique:serveur:web-linux-apache:https_www_apache2 [2023/02/09 17:14] (Version actuelle) – ↷ Liens modifiés en raison d'un déplacement. Cédric ABONNEL
Ligne 1: Ligne 1:
 +====== Configurer un site en https ======
 +{{  informatique:serveur:web-linux-apache:pasted:20210121-012842.png?300}}
 +Votre certificat a été généré grâce à **Certbot**. Il faut désormais configurer **Apache** pour utiliser de manière systématique ce certificat.
 +
 +Voici mes prises de notes pour passer un site Internet **http** en **https**. Le configuration est destinée pour un site Internet dont le sous-domaine est **www**. Il est très facilement adaptable pour un site avec un sous-domaine différent.
 +
 +<code>
 +  Configurer Apache 2
 +    http://www.perdu.com ==> https://www.perdu.com
 +</code>
 +
 +Je viens de demander un certificat SSL pour le site Internet ''perdu.com''. Il faut configurer Apache 2 pour que :
 +  * les demandes en https utilisent le certificat SSL
 +  * toutes les visites en http soit redirigées en https
 +
 +====== Configurer ======
 +
 +
 +Je complète le fichier de configuration ''/etc/apache2/sites-available/100-com.perdu.conf''. J'ajoute un bloc de redirection vers ''https'' :
 +
 +<code>
 +RewriteEngine On
 +RewriteCond %{HTTPS} off
 +RewriteCond %{REQUEST_URI} !\.well-known/acme-challenge/.*
 +RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 +</code>
 +
 +Puis, j'ajoute un bloc pour la configuration SSL / https. Il s'agit d'un copier/coller de la configuration http.
 +J'effectue quelques modifications :
 +  * [[linux:solutions_linux:configurer_un_site_web_apache_2:ErrorLog]] et [[linux:solutions_linux:configurer_un_site_web_apache_2:CustomLog]] pour l’écriture des fichiers logs
 +  * [[linux:solutions_linux:configurer_un_site_web_apache_2:RewriteRule]] pour la redirection des URL sans www
 +  * Ajout des options SSL
 +  * Ajout de la gestion des certificats
 +
 +<code>
 +<IfModule mod_ssl.c>
 +<VirtualHost *:443>
 +
 +    ServerName perdu.com
 +    ServerAlias www.perdu.com
 +    
 +    Protocols h2 http/1.1
 +
 +    DocumentRoot /var/www/perdu.com/www
 +
 +    <Directory /var/www/perdu.com/www>
 +        Options -Indexes +MultiViews
 +        AllowOverride all
 +        Order allow,deny
 +        allow from all
 +    </Directory>
 +
 +
 +    <Location />
 +        Require all granted
 +    </Location>
 +
 +    LogLevel warn
 +    ErrorLog ${APACHE_LOG_DIR}/www.perdu.com-https-error.log
 +    CustomLog ${APACHE_LOG_DIR}/www.perdu.com-https-access.log combined
 +
 +    SSLCertificateFile /etc/letsencrypt/live/www.perdu.com/fullchain.pem
 +    SSLCertificateKeyFile /etc/letsencrypt/live/www.perdu.com/privkey.pem
 +    SSLCertificateChainFile /etc/letsencrypt/live/www.perdu.com/chain.pem
 +    
 +    
 +</VirtualHost>
 +</IfModule>
 +
 +
 +</code>
 +
 +Les options SSL sont à créer une seule fois sur le serveur. Ces options sont communes à tous les sites Internet que je configure.
 +Les options dans ''/etc/apache2/mods-enabled/ssl.conf'' sont les suivantes :
 +<code>
 +
 +# Intermediate configuration
 +SSLProtocol -ALL +TLSv1.2
 +SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:!RC4:HIGH:!MD5:!aNULL:!EDH
 +SSLHonorCipherOrder     on
 +#SSLSessionTickets       off
 +
 +SSLOptions +StrictRequire
 +SSLCompression          off
 +
 +# HSTS (mod_headers is required) (15768000 seconds = 6 months)
 +Header always set Strict-Transport-Security "max-age=15768000"
 +
 +# Always ensure Cookies have "Secure" set (JAH 2012/1)
 +Header edit Set-Cookie (?i)^(.*)(;\s*secure)??((\s*;)?(.*)) "$1; Secure$3$4"
 +
 +</code>
 +
 +Il convient de désactiver ces options dans le fichier ''/etc/letsencrypt/options-ssl-apache.conf''
 +
 +----
 +
 +
 +Ce qui donne une configuration globale suivante :
 +
 +<code>
 +<VirtualHost *:80>
 +
 +    ServerName perdu.com
 +    ServerAlias www.perdu.com
 +    
 +    Protocols h2 http/1.1
 +
 +    DocumentRoot /var/www/perdu.com/www
 +
 +    <Directory /var/www/perdu.com/www>
 +        Options -Indexes +MultiViews
 +        AllowOverride all
 +        Order allow,deny
 +        allow from all
 +    </Directory>
 +
 +
 +    <Location />
 +        Require all granted
 +    </Location>
 +
 +    LogLevel warn
 +    ErrorLog ${APACHE_LOG_DIR}/www.perdu.com-http-error.log
 +    CustomLog ${APACHE_LOG_DIR}/www.perdu.com-http-access.log combined
 +
 +    # Redirection des URL vers https
 +    RewriteEngine On
 +    RewriteCond %{HTTPS} off
 +    RewriteCond %{REQUEST_URI} !\.well-known/acme-challenge/.*
 +    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 +
 +</VirtualHost>
 +
 +<IfModule mod_ssl.c>
 +<VirtualHost *:443>
 +
 +    ServerName perdu.com
 +    ServerAlias www.perdu.com
 +    
 +    Protocols h2 http/1.1
 +
 +    DocumentRoot /var/www/perdu.com/www
 +
 +    <Directory /var/www/perdu.com/www>
 +        Options -Indexes
 +        AllowOverride all
 +        Order allow,deny
 +        allow from all
 +    </Directory>
 +
 +
 +    <Location />
 +        Require all granted
 +    </Location>
 +
 +    LogLevel warn
 +    ErrorLog ${APACHE_LOG_DIR}/www.perdu.com-https-error.log
 +    CustomLog ${APACHE_LOG_DIR}/www.perdu.com-https-access.log combined
 +    
 +    SSLCertificateFile /etc/letsencrypt/live/www.perdu.com/fullchain.pem
 +    SSLCertificateKeyFile /etc/letsencrypt/live/www.perdu.com/privkey.pem
 +    SSLCertificateChainFile /etc/letsencrypt/live/www.perdu.com/chain.pem
 +   
 +
 +</VirtualHost>
 +</IfModule>
 +
 +
 +
 +</code>
 +
 +
 +====== Recharger ======
 +
 +Après ces modifications, je recharge la configuration de Apache 2 :
 +<code>
 +sudo service apache2 reload
 +</code>
 +
 +====== Zone DNS ======
 +
 +Il est possible d'ajouter une option dans la zone DNS pour sécuriser l'authenticité de l'organisme de certification.
 +Il s'agit du //DNS Certification Authority Authorization (CAA)// à activer grâce à un enregistrement **CAA** de la zone DNS :
 +  www               IN CAA    128 issue "letsencrypt.org"
 +  perdu.com.        IN CAA    128 issue "letsencrypt.org"
 +
 +
 +
 +====== Tester ======
 +
 +
 +Vous pouvez tester votre site grâce à l'outil https://www.ssllabs.com/ssltest/analyze.html
 +