index.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <link rel="shortcut icon" href="../../../img/favicon.ico">
  9. <title>Exemple d'utilisation avec un serveur Web - Les Tutoriels du Yojik</title>
  10. <link rel="stylesheet" href="../../../css/theme.css" />
  11. <link rel="stylesheet" href="../../../css/theme_extra.css" />
  12. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" />
  13. <script>
  14. // Current page data
  15. var mkdocs_page_name = "Exemple d'utilisation avec un serveur Web";
  16. var mkdocs_page_input_path = "Tutoriels/tutoraspi/Exemple-d-utilisation-serveur-Web.md";
  17. var mkdocs_page_url = null;
  18. </script>
  19. <script src="../../../js/jquery-2.1.1.min.js" defer></script>
  20. <script src="../../../js/modernizr-2.8.3.min.js" defer></script>
  21. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  22. <script>hljs.initHighlightingOnLoad();</script>
  23. </head>
  24. <body class="wy-body-for-nav" role="document">
  25. <div class="wy-grid-for-nav">
  26. <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
  27. <div class="wy-side-scroll">
  28. <div class="wy-side-nav-search">
  29. <a href="../../.." class="icon icon-home"> Les Tutoriels du Yojik</a>
  30. <div role="search">
  31. <form id ="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
  32. <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <p class="caption"><span class="caption-text">Home</span></p>
  38. <ul>
  39. <li class="toctree-l1"><a class="reference internal" href="../../..">Page d'accueil</a>
  40. </li>
  41. </ul>
  42. <p class="caption"><span class="caption-text">Tutoriels</span></p>
  43. <ul class="current">
  44. <li class="toctree-l1"><a class="reference internal" href="../../tutos/">Introduction</a>
  45. </li>
  46. <li class="toctree-l1"><a class="reference internal" href="#">Installation d'un serveur sécurisé, version Debian/Stretch (obsolète)</a>
  47. <ul>
  48. <li class="toctree-l2"><a class="reference internal" href="../../tutostretch/tutostretch/">Présentation</a>
  49. </li>
  50. <li class="toctree-l2"><a class="reference internal" href="#">Installation</a>
  51. <ul>
  52. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-de-base/">Installation du système de base</a>
  53. </li>
  54. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/ovh/">Démarrage sur serveur OVH</a>
  55. </li>
  56. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Premi%C3%A8re-Etape-S%C3%A9curisation/">Première étapes de sécurisation du serveur</a>
  57. </li>
  58. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Configuration-R%C3%A9seau/">Configuration du réseau</a>
  59. </li>
  60. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-Temps/">Installation d'un serveur de temps</a>
  61. </li>
  62. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Parre-Feu/">Installation d'un pare-feu</a>
  63. </li>
  64. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Fail2ban/">Contrer les attaques de brute-force avec fail2ban</a>
  65. </li>
  66. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-Courrier-Basique/">Installation d'un serveur de courrier basique</a>
  67. </li>
  68. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-DNS/">Installation du serveur DNS</a>
  69. </li>
  70. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-Web/">Installation d'un serveur web</a>
  71. </li>
  72. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Dovecot-Authentification/">Installation de dovecot et de l'authentification</a>
  73. </li>
  74. <li class="toctree-l3"><a class="" href="../../tutostretch/Installation-Certificats-Letsencrypt.md)">Installation des certificats letsencrypt</a>
  75. </li>
  76. <li class="toctree-l3"><a class="" href="../../tutostretch/courrier-SPF-DKIM-OPENDMARC.md">Ajout des enregistrements **spf**, **DKIM**, **DMARC** au fichier de zone DNS</a>
  77. </li>
  78. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Courrier-Comptes-Virtuels/">Ajout des comptes émail virtuels</a>
  79. </li>
  80. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Surveillance-Serveur/">Installation de programmes de surveillance du serveur</a>
  81. </li>
  82. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Webmail/">Installation d'un webmail (rainloop)</a>
  83. </li>
  84. <li class="toctree-l3"><a class="" href="../../tutostretch/Sécurisation-Serveur-Web">Sécurisation d'un serveur WEB</a>
  85. </li>
  86. </ul>
  87. </li>
  88. </ul>
  89. </li>
  90. <li class="toctree-l1"><a class="reference internal" href="#">Installation d'un serveur sécurisé, version Debian/Buster (en cours d'écriture)</a>
  91. <ul>
  92. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/1-tutobuster/">Présentation</a>
  93. </li>
  94. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/2-Installation-de-base/">Installation de base</a>
  95. </li>
  96. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/3-ovh/">Démarrage sur serveur OVH</a>
  97. </li>
  98. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/4-Plan/">Plan d'ensemble</a>
  99. </li>
  100. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/5-Premi%C3%A8re-Etape-S%C3%A9curisation/">Premières étapes de sécurisation du serveur</a>
  101. </li>
  102. </ul>
  103. </li>
  104. <li class="toctree-l1 current"><a class="reference internal current" href="#">Installation d'un serveur sécurisé, version Debian/Buster sur RaspberryPI</a>
  105. <ul class="current">
  106. <li class="toctree-l2"><a class="reference internal" href="../R%C3%A9sum%C3%A9/">Résumé</a>
  107. </li>
  108. <li class="toctree-l2"><a class="reference internal" href="../tutoraspi/">Présentation</a>
  109. </li>
  110. <li class="toctree-l2"><a class="reference internal" href="../Installation-de-base/">Installation de base</a>
  111. </li>
  112. <li class="toctree-l2"><a class="reference internal" href="../Premier-d%C3%A9marrage/">Premier démarrage</a>
  113. </li>
  114. <li class="toctree-l2"><a class="reference internal" href="../Etat-des-lieux/">État des lieux</a>
  115. </li>
  116. <li class="toctree-l2"><a class="reference internal" href="../S%C3%A9curisation-SSH/">Sécurisation SSH</a>
  117. </li>
  118. <li class="toctree-l2"><a class="reference internal" href="../R%C3%A9seau/">Réseau (des IPs fixes)</a>
  119. </li>
  120. <li class="toctree-l2"><a class="reference internal" href="../Knot/">Installation de Knot-resolver</a>
  121. </li>
  122. <li class="toctree-l2"><a class="reference internal" href="../Firewall/">Installation d'un pare-feux</a>
  123. </li>
  124. <li class="toctree-l2"><a class="reference internal" href="../Fail2ban/">Contrer les attaques de force brute</a>
  125. </li>
  126. <li class="toctree-l2"><a class="reference internal" href="../Logwatch/">Surveillance du serveur</a>
  127. </li>
  128. <li class="toctree-l2"><a class="reference internal" href="../Installation-courrier-basique/">Installation d'un serveur de courriers basique</a>
  129. </li>
  130. <li class="toctree-l2 current"><a class="reference internal current" href="./">Exemple d'utilisation avec un serveur Web</a>
  131. <ul class="current">
  132. <li class="toctree-l3"><a class="reference internal" href="#installation-du-programme">Installation du programme</a>
  133. <ul>
  134. <li class="toctree-l4"><a class="reference internal" href="#installation">Installation</a>
  135. </li>
  136. <li class="toctree-l4"><a class="reference internal" href="#ouverture-des-ports">Ouverture des ports</a>
  137. </li>
  138. <li class="toctree-l4"><a class="reference internal" href="#test">Test</a>
  139. </li>
  140. </ul>
  141. </li>
  142. <li class="toctree-l3"><a class="reference internal" href="#creation-de-la-page-daccueil">Création de la page d'accueil</a>
  143. <ul>
  144. <li class="toctree-l4"><a class="reference internal" href="#la-page-daccueil">La page d'accueil</a>
  145. </li>
  146. <li class="toctree-l4"><a class="reference internal" href="#creation-du-virtualhost-correspondant">Création du virtualhost correspondant</a>
  147. </li>
  148. <li class="toctree-l4"><a class="reference internal" href="#test-de-notre-page-daccueil">Test de notre page d'accueil</a>
  149. </li>
  150. </ul>
  151. </li>
  152. <li class="toctree-l3"><a class="reference internal" href="#securisation-de-notre-serveur">Sécurisation de notre serveur</a>
  153. <ul>
  154. <li class="toctree-l4"><a class="reference internal" href="#etat-des-lieux">État des lieux</a>
  155. </li>
  156. <li class="toctree-l4"><a class="reference internal" href="#test-de-notre-nouvelle-configuration">Test de notre nouvelle configuration</a>
  157. </li>
  158. <li class="toctree-l4"><a class="reference internal" href="#petites-ameliorations-supplementaires">Petites améliorations supplémentaires</a>
  159. </li>
  160. </ul>
  161. </li>
  162. </ul>
  163. </li>
  164. <li class="toctree-l2"><a class="reference internal" href="../Annexe/">Annexe</a>
  165. </li>
  166. </ul>
  167. </li>
  168. <li class="toctree-l1"><a class="reference internal" href="#">Domotique</a>
  169. <ul>
  170. <li class="toctree-l2"><a class="reference internal" href="../../Domotique/Introduction/">Introduction</a>
  171. </li>
  172. <li class="toctree-l2"><a class="reference internal" href="../../Domotique/Le-mat%C3%A9riel/">Le matériel</a>
  173. </li>
  174. </ul>
  175. </li>
  176. </ul>
  177. </div>
  178. </div>
  179. </nav>
  180. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  181. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  182. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  183. <a href="../../..">Les Tutoriels du Yojik</a>
  184. </nav>
  185. <div class="wy-nav-content">
  186. <div class="rst-content">
  187. <div role="navigation" aria-label="breadcrumbs navigation">
  188. <ul class="wy-breadcrumbs">
  189. <li><a href="../../..">Docs</a> &raquo;</li>
  190. <li>Installation d'un serveur sécurisé, version Debian/Buster sur RaspberryPI &raquo;</li>
  191. <li>Tutoriels &raquo;</li>
  192. <li>Exemple d'utilisation avec un serveur Web</li>
  193. <li class="wy-breadcrumbs-aside">
  194. </li>
  195. </ul>
  196. <hr/>
  197. </div>
  198. <div role="main">
  199. <div class="section">
  200. <h1 id="exemple-dutilisation-de-notre-tout-nouveau-raspi">Exemple d'utilisation de notre tout nouveau Raspi</h1>
  201. <p>Nous allons installer un serveur Web, <strong>apache</strong>.</p>
  202. <p>Ce n'est qu'un exemple : choisissez le logiciel que vous voulez, mais gardez à l'esprit la sécurisation.</p>
  203. <h2 id="installation-du-programme">Installation du programme</h2>
  204. <h3 id="installation">Installation</h3>
  205. <pre><code>pi@piras:~ $ sudo apt install apache2
  206. Lecture des listes de paquets... Fait
  207. Construction de l'arbre des dépendances
  208. Lecture des informations d'état... Fait
  209. Les paquets supplémentaires suivants seront installés :
  210. apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 liblua5.2-0
  211. Paquets suggérés :
  212. apache2-doc apache2-suexec-pristine | apache2-suexec-custom
  213. Les NOUVEAUX paquets suivants seront installés :
  214. apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1
  215. liblua5.2-0
  216. 0 mis à jour, 10 nouvellement installés, 0 à enlever et 0 non mis à jour.
  217. Il est nécessaire de prendre 2 309 ko dans les archives.
  218. Après cette opération, 7 253 ko d'espace disque supplémentaires seront utilisés.
  219. Souhaitez-vous continuer ? [O/n] o
  220. ...
  221. Enabling site 000-default.
  222. Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
  223. Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.
  224. service.
  225. Traitement des actions différées (« triggers ») pour systemd (241-7~deb10u6+rpi1) ...
  226. Traitement des actions différées (« triggers ») pour man-db (2.8.5-2) ...
  227. Traitement des actions différées (« triggers ») pour libc-bin (2.28-10+rpi1) ...
  228. pi@piras:~ $
  229. </code></pre>
  230. <h3 id="ouverture-des-ports">Ouverture des ports</h3>
  231. <p>Il nous faut ajouter les services <strong>http</strong> et <strong>https</strong>.</p>
  232. <ol>
  233. <li>
  234. <p>Règles en cours</p>
  235. <pre><code>pi@piras:~ $ sudo firewall-cmd --state
  236. running
  237. pi@piras:~ $ sudo firewall-cmd --get-default-zone
  238. public
  239. pi@piras:~ $ sudo firewall-cmd --get-active-zones
  240. public
  241. interfaces: eth0
  242. pi@piras:~ $ sudo firewall-cmd --list-all
  243. public (active)
  244. target: default
  245. icmp-block-inversion: no
  246. interfaces: eth0
  247. sources:
  248. services: dhcpv6-client smtp ssh
  249. ports:
  250. protocols:
  251. masquerade: no
  252. forward-ports:
  253. source-ports:
  254. icmp-blocks:
  255. rich rules:
  256. </code></pre>
  257. </li>
  258. <li>
  259. <p>Ajout des services</p>
  260. <pre><code>pi@piras:~ $ sudo firewall-cmd --permanent --zone=public --add-service={http,https}
  261. success
  262. pi@piras:~ $
  263. </code></pre>
  264. </li>
  265. <li>
  266. <p>Test de nos services actifs</p>
  267. <p>J'ai relancé le raspi car j'avais des erreurs de <strong>zones</strong>.</p>
  268. <p>Après redémarrage, tout est bon :</p>
  269. <pre><code>pi@piras:~ $ sudo firewall-cmd --list-all
  270. public (active)
  271. target: default
  272. icmp-block-inversion: no
  273. interfaces: eth0
  274. sources:
  275. services: dhcpv6-client http https smtp ssh
  276. ports:
  277. protocols:
  278. masquerade: no
  279. forward-ports:
  280. source-ports:
  281. icmp-blocks:
  282. rich rules:
  283. pi@piras:~ $
  284. </code></pre>
  285. <p>Nos services <strong>http</strong> et <strong>https</strong> ont bien été pris en compte.</p>
  286. </li>
  287. </ol>
  288. <h3 id="test">Test</h3>
  289. <p>Nous allons faire un test de connexion :</p>
  290. <p><img alt="Page d'accueil de Debian" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2008-34-27.png" /></p>
  291. <p>Tout fonctionne comme il faut.</p>
  292. <h2 id="creation-de-la-page-daccueil">Création de la page d'accueil</h2>
  293. <h3 id="la-page-daccueil">La page d'accueil</h3>
  294. <p>Nous allons créer un petit fichier <strong>.html</strong> pour personnaliser notre page d'acceuil. Le fichier s'appellera <strong>index.html</strong> et est situé dans <strong>/var/www/html/</strong>.</p>
  295. <pre><code>pi@piras:~ $ cd /var/www/html/
  296. pi@piras:/var/www/html $ ls
  297. index.html
  298. pi@piras:/var/www/html $
  299. </code></pre>
  300. <p>Avec votre éditeur favori, supprimez le fichier :</p>
  301. <pre><code>pi@piras:/var/www/html $ sudo rm index.html
  302. pi@piras:/var/www/html $
  303. </code></pre>
  304. <p>et créez un nouveau fichier dont le contenu est le suivant :</p>
  305. <pre><code>&lt;!DOCTYPE html&gt;
  306. &lt;html&gt;
  307. &lt;head&gt;
  308. &lt;title&gt;Page d'accueil du Piras&lt;/title&gt;
  309. &lt;meta charset="UTF-8"&gt;
  310. &lt;/head&gt;
  311. &lt;body&gt;
  312. &lt;h1&gt;Page d'acceuil du Piras&lt;/h1&gt;
  313. &lt;p&gt;Vous voilà sur la page principale de notre tout nouveau serveur Web.&lt;/p&gt;
  314. &lt;p&gt;Merci de votre visite!&lt;/p&gt;
  315. &lt;/body&gt;
  316. &lt;/html&gt;
  317. pi@piras:/var/www/html $ sudo vim index.html
  318. pi@piras:/var/www/html $
  319. </code></pre>
  320. <p>Changez le propriétaire du fichier :</p>
  321. <pre><code>pi@piras:/var/www/html $ sudo chown www-data: index.html
  322. pi@piras:/var/www/html $
  323. </code></pre>
  324. <h3 id="creation-du-virtualhost-correspondant">Création du <strong>virtualhost</strong> correspondant</h3>
  325. <pre><code>pi@piras:/etc/apache2/sites-available $ cat piras.conf
  326. &lt;VirtualHost *:80&gt;
  327. ServerName piras.yojik.net
  328. ServerAdmin webmaster@localhost
  329. DocumentRoot /var/www/html
  330. ErrorLog ${APACHE_LOG_DIR}/error.log
  331. CustomLog ${APACHE_LOG_DIR}/access.log combined
  332. &lt;/VirtualHost&gt;
  333. pi@piras:/etc/apache2/sites-available $
  334. </code></pre>
  335. <p>On désactive les anciens sites par défaut, et on active le nouveau :</p>
  336. <pre><code>pi@piras:/etc/apache2/sites-available $ sudo a2dissite default-ssl
  337. Site default-ssl disabled.
  338. To activate the new configuration, you need to run:
  339. systemctl reload apache2
  340. pi@piras:/etc/apache2/sites-available $ sudo a2dissite 000-default
  341. Site 000-default disabled.
  342. To activate the new configuration, you need to run:
  343. systemctl reload apache2
  344. pi@piras:/etc/apache2/sites-available $
  345. pi@piras:/etc/apache2/sites-available $ sudo a2ensite piras
  346. Enabling site piras.
  347. To activate the new configuration, you need to run:
  348. systemctl reload apache2
  349. pi@piras:/etc/apache2/sites-available $
  350. </code></pre>
  351. <p>On recharge apache2 pour qu'il prenne en compte nos modifications :</p>
  352. <pre><code>pi@piras:/etc/apache2/sites-available $ sudo systemctl reload apache2
  353. pi@piras:/etc/apache2/sites-available $
  354. </code></pre>
  355. <h3 id="test-de-notre-page-daccueil">Test de notre page d'accueil</h3>
  356. <p><img alt="Page d'accueil du Piras" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2009-04-24.png" /></p>
  357. <p>Et voilà! :D</p>
  358. <h2 id="securisation-de-notre-serveur">Sécurisation de notre serveur</h2>
  359. <h3 id="etat-des-lieux">État des lieux</h3>
  360. <p>Rendez-vous sur la page suivante : <a href="https://observatory.mozilla.org/">Test Mozilla</a>. Nos résultats ne sont pas terribles ...</p>
  361. <p><img alt="Résultat 1" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2009-15-59.png" /></p>
  362. <p><img alt="Résultat 2" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2009-16-17.png" /></p>
  363. <p><img alt="Résultat 3" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2009-16-52.png" /></p>
  364. <p>Nous allons suivre les recommandations de la fondation <strong>Mozilla</strong> en ce qui concerne les algorithmes utilisés pour le chiffrement.</p>
  365. <p>Page de configuration d'un serveur Apache par la fondation <strong>Mozilla</strong> : <a href="https://ssl-config.mozilla.org/#server=apache&amp;version=2.4.41&amp;config=intermediate&amp;openssl=1.1.1d&amp;guideline=5.6">Configurateur</a></p>
  366. <p>Nous alons donc éditer notre fichier <strong>piras.conf</strong> situé dans <strong>/etc/apache2/sites-available/</strong> ainsi que le fichier général de configuration d'apache, situé dans pi@piras:/etc/apache2, <strong>apache2.conf</strong> :</p>
  367. <ol>
  368. <li>
  369. <p>Sauvegarde des fichiers existants</p>
  370. <p>pi@piras:/etc/apache2 $ sudo cp apache2.conf apache2.conf.orig
  371. pi@piras:/etc/apache2 $</p>
  372. </li>
  373. <li>
  374. <p>Création de certificats let'encrypt</p>
  375. <p>Il existe plusieurs clients <strong>letsencrypt</strong> pour la gestion des certificats. Nous utiliserons <strong>certbot</strong>, le client officiel de <strong>letsencrypt</strong>.</p>
  376. <pre><code>pi@piras:~ $ sudo apt install certbot python-certbot-apache
  377. ...
  378. pi@piras:~ $
  379. </code></pre>
  380. <p>Nous stoppons le service <strong>apache</strong></p>
  381. <pre><code>pi@piras:~ $ sudo systemctl stop apache2
  382. pi@piras:~ $
  383. </code></pre>
  384. <p>Lançons <strong>certbot</strong></p>
  385. <pre><code>pi@piras:~ $ sudo certbot
  386. Saving debug log to /var/log/letsencrypt/letsencrypt.log
  387. Plugins selected: Authenticator apache, Installer apache
  388. Enter email address (used for urgent renewal and security notices) (Enter 'c' to
  389. cancel): eric@yojik.eu
  390. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  391. Please read the Terms of Service at
  392. https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
  393. agree in order to register with the ACME server at
  394. https://acme-v02.api.letsencrypt.org/directory
  395. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  396. (A)gree/(C)ancel: A
  397. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  398. Would you be willing to share your email address with the Electronic Frontier
  399. Foundation, a founding partner of the Let's Encrypt project and the non-profit
  400. organization that develops Certbot? We'd like to send you email about our work
  401. encrypting the web, EFF news, campaigns, and ways to support digital freedom.
  402. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  403. (Y)es/(N)o: Y
  404. Which names would you like to activate HTTPS for?
  405. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  406. 1: piras.yojik.net
  407. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  408. Select the appropriate numbers separated by commas and/or spaces, or leave input
  409. blank to select all options shown (Enter 'c' to cancel): 1
  410. Obtaining a new certificate
  411. Performing the following challenges:
  412. http-01 challenge for piras.yojik.net
  413. Waiting for verification...
  414. Cleaning up challenges
  415. Created an SSL vhost at /etc/apache2/sites-available/piras-le-ssl.conf
  416. Deploying Certificate to VirtualHost /etc/apache2/sites-available/piras-le-ssl.conf
  417. Enabling available site: /etc/apache2/sites-available/piras-le-ssl.conf
  418. Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
  419. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  420. 1: No redirect - Make no further changes to the webserver configuration.
  421. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
  422. new sites, or if you're confident your site works on HTTPS. You can undo this
  423. change by editing your web server's configuration.
  424. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  425. Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
  426. Redirecting vhost in /etc/apache2/sites-enabled/piras.conf to ssl vhost in /etc/apache2/sites-available/piras-le-ssl.conf
  427. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  428. Congratulations! You have successfully enabled https://piras.yojik.net
  429. You should test your configuration at:
  430. https://www.ssllabs.com/ssltest/analyze.html?d=piras.yojik.net
  431. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  432. IMPORTANT NOTES:
  433. - Congratulations! Your certificate and chain have been saved at:
  434. /etc/letsencrypt/live/piras.yojik.net/fullchain.pem
  435. Your key file has been saved at:
  436. /etc/letsencrypt/live/piras.yojik.net/privkey.pem
  437. Your cert will expire on 2021-06-05. To obtain a new or tweaked
  438. version of this certificate in the future, simply run certbot again
  439. with the "certonly" option. To non-interactively renew *all* of
  440. your certificates, run "certbot renew"
  441. - Your account credentials have been saved in your Certbot
  442. configuration directory at /etc/letsencrypt. You should make a
  443. secure backup of this folder now. This configuration directory will
  444. also contain certificates and private keys obtained by Certbot so
  445. making regular backups of this folder is ideal.
  446. - If you like Certbot, please consider supporting our work by:
  447. Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
  448. Donating to EFF: https://eff.org/donate-le
  449. pi@piras:~ $
  450. </code></pre>
  451. <p>Relançons <strong>apache</strong></p>
  452. <pre><code>pi@piras:~ $ sudo systemctl start apache2
  453. pi@piras:~ $
  454. </code></pre>
  455. </li>
  456. <li>
  457. <p>Premier test</p>
  458. <p><img alt="Test avec SSL" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2015-24-01.png" /></p>
  459. <p>C'est bon.</p>
  460. </li>
  461. <li>
  462. <p>Sécurisation du serveur <strong>apache</strong></p>
  463. <ul>
  464. <li>
  465. <p>Strict-Transport-Security</p>
  466. <p>Ajouter la ligne suivante à piras.conf :</p>
  467. <pre><code>Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
  468. </code></pre>
  469. </li>
  470. <li>
  471. <p>Content-Security-Policy</p>
  472. <p>Ajouter la ligne suivante à piras.conf :</p>
  473. <pre><code>Header set Content-Security-Policy "default-src 'self';"
  474. </code></pre>
  475. </li>
  476. <li>
  477. <p>X-Content-Type-Options</p>
  478. <p>Ajouter la ligne suivante à piras.conf :</p>
  479. <pre><code>&lt;IfModule mod_headers.c&gt;
  480. Header set X-Content-Type-Options "nosniff"
  481. &lt;/IfModule&gt;
  482. </code></pre>
  483. <p>Il faut activer aussi le module headers (déjà activé chez moi) :</p>
  484. <pre><code>pi@piras:~ $ sudo a2enmod headers
  485. Module headers already enabled
  486. pi@piras:~ $
  487. </code></pre>
  488. </li>
  489. <li>
  490. <p>X-Frame-Options</p>
  491. <p>Ajouter la ligne suivante à piras.conf :</p>
  492. <pre><code>&lt;IfModule mod_headers.c&gt;
  493. Header set X-Content-Type-Options "nosniff"
  494. &lt;/IfModule&gt;
  495. </code></pre>
  496. </li>
  497. <li>
  498. <p>X-XSS-Protection</p>
  499. <p>Ajouter la ligne suivante à piras.conf :</p>
  500. <pre><code>Header set X-Frame-Options: "SAMEORIGIN"
  501. </code></pre>
  502. </li>
  503. </ul>
  504. <p>Voilà le contenu du fichier après modifications :</p>
  505. <pre><code>pi@piras:~ $ cat /etc/apache2/sites-available/piras-le-ssl.conf
  506. &lt;IfModule mod_ssl.c&gt;
  507. &lt;VirtualHost *:443&gt;
  508. Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
  509. Header set Content-Security-Policy "default-src 'self';"
  510. &lt;IfModule mod_headers.c&gt;
  511. Header set X-Content-Type-Options "nosniff"
  512. &lt;/IfModule&gt;
  513. Header set X-Frame-Options: "SAMEORIGIN"
  514. ServerName piras.yojik.net
  515. ServerAdmin webmaster@localhost
  516. DocumentRoot /var/www/html
  517. ErrorLog ${APACHE_LOG_DIR}/error.log
  518. CustomLog ${APACHE_LOG_DIR}/access.log combined
  519. SSLCertificateFile /etc/letsencrypt/live/piras.yojik.net/fullchain.pem
  520. SSLCertificateKeyFile /etc/letsencrypt/live/piras.yojik.net/privkey.pem
  521. Include /etc/letsencrypt/options-ssl-apache.conf
  522. &lt;/VirtualHost&gt;
  523. &lt;/IfModule&gt;
  524. pi@piras:~ $
  525. </code></pre>
  526. </li>
  527. </ol>
  528. <h3 id="test-de-notre-nouvelle-configuration">Test de notre nouvelle configuration</h3>
  529. <p>Cette fois-ci, nous obtenons la note maximale A+ :</p>
  530. <p><img alt="Test avec SSL" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2018-13-31.png" /></p>
  531. <p><img alt="Test avec SSL" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2018-13-51.png" /></p>
  532. <p><img alt="Test avec SSL" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-07%2018-14-43.png" /></p>
  533. <p>Nous sommes passés d'une note <strong>F</strong> à <strong>A+</strong>!</p>
  534. <h3 id="petites-ameliorations-supplementaires">Petites améliorations supplémentaires</h3>
  535. <ul>
  536. <li>
  537. <p>cacher les données du serveur</p>
  538. <p>Cela se configure dans le fichier <strong>/etc/apache2/conf-available/security.conf</strong></p>
  539. <p>J'ai modifié les lignes suivantes : </p>
  540. <pre><code>ServerSignature Off
  541. ServerTokens Prod
  542. </code></pre>
  543. <p>Sauvegarde du fichier et relance du serveur apache.</p>
  544. <p><img alt="Avant" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-08%2009-18-18.png" /></p>
  545. <p><img alt="Après" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-08%2009-18-28.png" /></p>
  546. <p>On peut constater que notre serveur ne divulgue plus d'informations sur son type, ni sur l'OS utilisé.</p>
  547. </li>
  548. <li>
  549. <p>le parcours des répertoires</p>
  550. <p>Nous allons interdire le parcours des répertoires/sous-répertoires, de telle façon que le visiteur ne puisse plus voir les fichiers/répertoires.</p>
  551. <p>Procédure de test : </p>
  552. <p>Nous allons créer un répertoire <strong>test</strong> avec 2 fichiers (vides) dans l'arboresence de notre site Web.</p>
  553. <pre><code>pi@piras:/etc/apache2/conf-available $ cd /var/www/html/
  554. pi@piras:/var/www/html $ sudo mkdir test
  555. pi@piras:/var/www/html $ cd test
  556. pi@piras:/var/www/html/test $ sudo touch fichier1 fichier2
  557. pi@piras:/var/www/html/test $
  558. </code></pre>
  559. <p>Le résultat est le suivant :</p>
  560. <p><img alt="Avant" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-08%2009-25-25.png" /></p>
  561. <p>Retournons dans notre fichier précédent et modifions-le pour avoir ceci :</p>
  562. <pre><code>&lt;Directory /var/www/html&gt;
  563. # AllowOverride None
  564. # Require all denied
  565. Options None
  566. &lt;/Directory&gt;
  567. </code></pre>
  568. <p>Relançons apache et voyons le résultat :</p>
  569. <p><img alt="Après" src="../../../Images/tutoraspi/Capture%20d%E2%80%99%C3%A9cran%20de%202021-03-08%2009-31-20.png" /></p>
  570. <p>Le visiteur n'a plus accès au listage des répertoires.</p>
  571. </li>
  572. <li>
  573. <p>protection contre les informations données par l'entête (header) <strong>Etag</strong></p>
  574. <p>Il nous faut rajouter la directive suivante au fichier de configuration :</p>
  575. <pre><code>FileEtag None
  576. </code></pre>
  577. </li>
  578. <li>
  579. <p>limitation des requêtes possibles : </p>
  580. <p>les méthodes supportées sont nombreuses et peuvent être configurées site par site. Mais en général, pour un site statique comme celui-là, seules les méthodes <strong>GET</strong>, <strong>Head</strong>, et <strong>POST</strong> sont nécessaires.</p>
  581. <p>Modification du fichier précédent</p>
  582. <pre><code>&lt;Directory /var/www/html&gt;
  583. # AllowOverride None
  584. # Require all denied
  585. Options None
  586. &lt;LimitExcept GET POST OPTIONS&gt;
  587. Require all denied
  588. &lt;/LimitExcept&gt;
  589. &lt;/Directory&gt;S
  590. </code></pre>
  591. </li>
  592. <li>
  593. <p>interdire la requête Trace</p>
  594. <p>C'est déjà mis en place par défaut dans la configuration Debian.</p>
  595. </li>
  596. </ul>
  597. <p>Voilà pour quelques améliorations de la sécurité de notre serveur Web.</p>
  598. </div>
  599. </div>
  600. <footer>
  601. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  602. <a href="../Annexe/" class="btn btn-neutral float-right" title="Annexe">Next <span class="icon icon-circle-arrow-right"></span></a>
  603. <a href="../Installation-courrier-basique/" class="btn btn-neutral" title="Installation d'un serveur de courriers basique"><span class="icon icon-circle-arrow-left"></span> Previous</a>
  604. </div>
  605. <hr/>
  606. <div role="contentinfo">
  607. <!-- Copyright etc -->
  608. </div>
  609. Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
  610. </footer>
  611. </div>
  612. </div>
  613. </section>
  614. </div>
  615. <div class="rst-versions" role="note" aria-label="versions">
  616. <span class="rst-current-version" data-toggle="rst-current-version">
  617. <span><a href="../Installation-courrier-basique/" style="color: #fcfcfc;">&laquo; Previous</a></span>
  618. <span style="margin-left: 15px"><a href="../Annexe/" style="color: #fcfcfc">Next &raquo;</a></span>
  619. </span>
  620. </div>
  621. <script>var base_url = '../../..';</script>
  622. <script src="../../../js/theme.js" defer></script>
  623. <script src="../../../search/main.js" defer></script>
  624. <script defer>
  625. window.onload = function () {
  626. SphinxRtdTheme.Navigation.enable(true);
  627. };
  628. </script>
  629. </body>
  630. </html>