Files
varlog/_cache/articles/c5c2eafb-a762-48d1-b956-81e473e02efd.json
T
2026-05-15 10:37:48 +02:00

1 line
5.8 KiB
JSON

{"uuid":"c5c2eafb-a762-48d1-b956-81e473e02efd","slug":"https-www-apache2","title":"Configurer un site en https","author":"cedric@abonnel.fr","published":true,"published_at":"2023-02-09 16:14:06","created_at":"2023-02-09 16:14:06","updated_at":"2023-02-09 16:14:06","revisions":[],"cover":"","files_meta":[],"external_links":[],"seo_title":"","seo_description":"","og_image":"","category":"Informatique","content":"# Configurer un site en https\n\n![](20210121-012842.png)\nVotre certificat a été généré grâce à **Certbot**. Il faut désormais configurer **Apache** pour utiliser de manière systématique ce certificat.\n\nVoici 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.\n\n```\nConfigurer Apache 2\n http:*www.perdu.com ==> https:*www.perdu.com\n```\n\nJe viens de demander un certificat SSL pour le site Internet `perdu.com`. Il faut configurer Apache 2 pour que :\n- les demandes en https utilisent le certificat SSL\n- toutes les visites en http soit redirigées en https\n\n# Configurer\nJe complète le fichier de configuration `/etc/apache2/sites-available/100-com.perdu.conf`. J'ajoute un bloc de redirection vers `https` :\n\n```\nRewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteCond %{REQUEST_URI} !\\.well-known/acme-challenge/.*\nRewriteRule ^(.*)$ https:*%{HTTP_HOST}%{REQUEST_URI} [R=301,L]\n```\n\nPuis, j'ajoute un bloc pour la configuration SSL / https. Il s'agit d'un copier/coller de la configuration http.\nJ'effectue quelques modifications :\n- et pour l’écriture des fichiers logs\n- pour la redirection des URL sans www\n- Ajout des options SSL\n- Ajout de la gestion des certificats\n\n```\n<IfModule mod_ssl.c>\n<VirtualHost *:443>\n\n ServerName perdu.com\n ServerAlias www.perdu.com\n \n Protocols h2 http/1.1\n\n DocumentRoot /var/www/perdu.com/www\n\n <Directory /var/www/perdu.com/www>\n Options -Indexes +MultiViews\n AllowOverride all\n Order allow,deny\n allow from all\n </Directory>\n\n <Location />\n Require all granted\n </Location>\n\n LogLevel warn\n ErrorLog ${APACHE_LOG_DIR}/www.perdu.com-https-error.log\n CustomLog ${APACHE_LOG_DIR}/www.perdu.com-https-access.log combined\n\n SSLCertificateFile /etc/letsencrypt/live/www.perdu.com/fullchain.pem\n SSLCertificateKeyFile /etc/letsencrypt/live/www.perdu.com/privkey.pem\n SSLCertificateChainFile /etc/letsencrypt/live/www.perdu.com/chain.pem\n \n \n</VirtualHost>\n</IfModule>\n```\n\nLes options SSL sont à créer une seule fois sur le serveur. Ces options sont communes à tous les sites Internet que je configure.\nLes options dans `/etc/apache2/mods-enabled/ssl.conf` sont les suivantes :\n```\n# Intermediate configuration\nSSLProtocol -ALL +TLSv1.2\nSSLCipherSuite 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\nSSLHonorCipherOrder on\n#SSLSessionTickets off\n\nSSLOptions +StrictRequire\nSSLCompression off\n\n# HSTS (mod_headers is required) (15768000 seconds = 6 months)\nHeader always set Strict-Transport-Security \"max-age=15768000\"\n\n# Always ensure Cookies have \"Secure\" set (JAH 2012/1)\nHeader edit Set-Cookie (?i)^(.*)(;\\s*secure)??[^note: \\s*;)?(.*] \"$1; Secure$3$4\"\n```\n\nIl convient de désactiver ces options dans le fichier `/etc/letsencrypt/options-ssl-apache.conf`\n\n---\nCe qui donne une configuration globale suivante :\n\n```\n<VirtualHost *:80>\n\n ServerName perdu.com\n ServerAlias www.perdu.com\n \n Protocols h2 http/1.1\n\n DocumentRoot /var/www/perdu.com/www\n\n <Directory /var/www/perdu.com/www>\n Options -Indexes +MultiViews\n AllowOverride all\n Order allow,deny\n allow from all\n </Directory>\n\n <Location />\n Require all granted\n </Location>\n\n LogLevel warn\n ErrorLog ${APACHE_LOG_DIR}/www.perdu.com-http-error.log\n CustomLog ${APACHE_LOG_DIR}/www.perdu.com-http-access.log combined\n\n # Redirection des URL vers https\n RewriteEngine On\n RewriteCond %{HTTPS} off\n RewriteCond %{REQUEST_URI} !\\.well-known/acme-challenge/.*\n RewriteRule ^(.*)$ https:*%{HTTP_HOST}%{REQUEST_URI} [R=301,L]\n\n</VirtualHost>\n\n<IfModule mod_ssl.c>\n<VirtualHost *:443>\n\n ServerName perdu.com\n ServerAlias www.perdu.com\n \n Protocols h2 http/1.1\n\n DocumentRoot /var/www/perdu.com/www\n\n <Directory /var/www/perdu.com/www>\n Options -Indexes\n AllowOverride all\n Order allow,deny\n allow from all\n </Directory>\n\n <Location />\n Require all granted\n </Location>\n\n LogLevel warn\n ErrorLog ${APACHE_LOG_DIR}/www.perdu.com-https-error.log\n CustomLog ${APACHE_LOG_DIR}/www.perdu.com-https-access.log combined\n \n SSLCertificateFile /etc/letsencrypt/live/www.perdu.com/fullchain.pem\n SSLCertificateKeyFile /etc/letsencrypt/live/www.perdu.com/privkey.pem\n SSLCertificateChainFile /etc/letsencrypt/live/www.perdu.com/chain.pem\n \n\n</VirtualHost>\n</IfModule>\n```\n\n# Recharger\nAprès ces modifications, je recharge la configuration de Apache 2 :\n```\nsudo service apache2 reload\n```\n\n# Zone DNS\nIl est possible d'ajouter une option dans la zone DNS pour sécuriser l'authenticité de l'organisme de certification.\nIl s'agit du *DNS Certification Authority Authorization (CAA)* à activer grâce à un enregistrement **CAA** de la zone DNS :\n www IN CAA 128 issue \"letsencrypt.org\"\n perdu.com. IN CAA 128 issue \"letsencrypt.org\"\n\n# Tester\nVous pouvez tester votre site grâce à l'outil https://www.ssllabs.com/ssltest/analyze.html","featured":false,"tags":[]}