issue102:tutoriel_2
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue102:tutoriel_2 [2015/11/01 18:55] – créée auntiee | issue102:tutoriel_2 [2015/11/16 18:49] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Now that our Linux VM is built and secure, it's time to install the web server. | + | **Now that our Linux VM is built and secure, it's time to install the web server. |
What exactly is a web server? | What exactly is a web server? | ||
Ligne 5: | Ligne 5: | ||
A web server is software which serves web pages (and potentially other files – for example binaries – like videos, packages, … etc). | A web server is software which serves web pages (and potentially other files – for example binaries – like videos, packages, … etc). | ||
- | And how does this really actually work? The web server runs as a daemon. “Daemon” - at least in the *nix family – means software that runs in background (meaning there is typically no output on the screen, the program runs silently without interaction from the user), and typically listens on a TCP port (more on TCP ports in part 2, published last week). | + | And how does this really actually work? The web server runs as a daemon. “Daemon” - at least in the *nix family – means software that runs in background (meaning there is typically no output on the screen, the program runs silently without interaction from the user), and typically listens on a TCP port (more on TCP ports in part 2, published last week).** |
- | When a request is sent to that specific listening port, the daemon wakes up and produces an action – for a web server, the daemon typically sends back a web page. | + | Maintenant que notre machine virtuelle Linux est construite et sûre, il est temps d' |
+ | |||
+ | Qu' | ||
+ | |||
+ | Un serveur Web est un logiciel qui délivre des pages Web (et potentiellement d' | ||
+ | |||
+ | Et comment cela fonctionne-t-il réellement ? | ||
+ | |||
+ | **When a request is sent to that specific listening port, the daemon wakes up and produces an action – for a web server, the daemon typically sends back a web page. | ||
Which web server to choose? | Which web server to choose? | ||
Ligne 15: | Ligne 23: | ||
Apache has been around for longer and has the largest market share. Ngix is supposed to be lighter and therefore maybe faster. | Apache has been around for longer and has the largest market share. Ngix is supposed to be lighter and therefore maybe faster. | ||
- | I chose Apache for this tutorial – there is no specific reason why not ngix, which is also an excellent server, other than I personally have more exposure with Apache software in general. | + | I chose Apache for this tutorial – there is no specific reason why not ngix, which is also an excellent server, other than I personally have more exposure with Apache software in general.** |
- | Install Apache Web Server | + | Quand une requête est envoyée sur ce port particulier, |
+ | |||
+ | Quel serveur Web choisir ? | ||
+ | |||
+ | Les serveurs les plus populaires sont Apache, ngix, Microsoft et Google (liste recueillie chez netcraft.com). Je ne suis pas très habitué à Google en matière de serveur et Microsoft est à priori hors liste (imaginez pourquoi !). Il nous reste donc à choisir entre Apache et ngix. | ||
+ | |||
+ | Apache existe depuis plus longtemps et possède la plus grande part du marché. Ngix est, semble-t-il, | ||
+ | |||
+ | J'ai choisi Apache pour ce tutoriel – je n'ai aucune raison particulière de n' | ||
+ | |||
+ | |||
+ | **Install Apache Web Server | ||
Before we start, note that I will also add the commands for Centos7. | Before we start, note that I will also add the commands for Centos7. | ||
Ligne 27: | Ligne 46: | ||
Make sure to answer Y to continue (or hit enter) | Make sure to answer Y to continue (or hit enter) | ||
- | We can now check that the web-server started properly (shown below) - using a web browser, key the IP address of the server (in my example it is 159.203.90.111). | + | We can now check that the web-server started properly (shown below) - using a web browser, key the IP address of the server (in my example it is 159.203.90.111).** |
+ | |||
+ | Installer le serveur Web d' | ||
+ | |||
+ | Avant de commencer, notez que je vais également ajouter les commandes pour Centos7. | ||
+ | |||
+ | Installer un serveur Web est aussi facile que d' | ||
+ | |||
+ | sudo apt-get install apache2 (Centos7 – yum install httpd) | ||
+ | |||
+ | Assurez-vous de répondre Y pour continuer (ou d' | ||
+ | |||
+ | On peut maintenant s' | ||
- | Configuration and tuning | + | **Configuration and tuning |
Now that Apache is installed, we must tune, configure and secure the web server. | Now that Apache is installed, we must tune, configure and secure the web server. | ||
Ligne 55: | Ligne 86: | ||
What does this all mean? | What does this all mean? | ||
+ | |||
• StartServers defines the minimum number of child server processes created when web server starts. 2 works well for me, not sure what the default is. | • StartServers defines the minimum number of child server processes created when web server starts. 2 works well for me, not sure what the default is. | ||
+ | |||
+ | |||
• MinSpareServers is the minimum number of threads waiting for requests while MaxSpareServers is the maximum number. Higher the number, more load the server can handle, however we have to balance the values with our server resources (1 CPU & 512MB of RAM). 6 and 12 work well here. | • MinSpareServers is the minimum number of threads waiting for requests while MaxSpareServers is the maximum number. Higher the number, more load the server can handle, however we have to balance the values with our server resources (1 CPU & 512MB of RAM). 6 and 12 work well here. | ||
+ | |||
• MaxClients is the max number of simultaneous requests that will be served (any additional will be queued). 80 works well here. | • MaxClients is the max number of simultaneous requests that will be served (any additional will be queued). 80 works well here. | ||
- | • MaxRequestsPerChild is the threshold after which a child process will re-spawn. For example, as any software, Apache can have memory leaks – so restarting the child process after a given number of requests served will clean up potentially leaked resources. | ||
- | Disable default site | + | • MaxRequestsPerChild is the threshold after which a child process will re-spawn. For example, as any software, Apache can have memory leaks – so restarting the child process after a given number of requests served will clean up potentially leaked resources.** |
+ | |||
+ | Configuration et réglage | ||
+ | |||
+ | Maintenant qu' | ||
+ | |||
+ | D' | ||
+ | |||
+ | Théoriquement, | ||
+ | |||
+ | Éditez le fichier : / | ||
+ | |||
+ | sudo vi / | ||
+ | |||
+ | < | ||
+ | StartServers 2 | ||
+ | MinSpareServers 6 | ||
+ | MaxSpareServers 12 | ||
+ | MaxClients 80 | ||
+ | MaxRequestsPerChild 3000 | ||
+ | </ | ||
+ | |||
+ | Pour que cela fasse effet, enregistrez le fichier et redémarrez le service Apache en tapant : | ||
+ | |||
+ | sudo service apache2 restart (Centos7: systemctl restart httpd) | ||
+ | |||
+ | Que signifie tout cela ? | ||
+ | • StartServers définit le nombre minimum de serveurs enfants créés quand le serveur Web démarre. 2 fonctionne très bien pour moi et je ne sais pas exactement quelle est la valeur par défaut. | ||
+ | • MinSpareServers est le nombre minimum de fils qui attendent des requêtes alors que MaxSpareServers est son nombre maximum. Plus le nombre est élevé et plus la charge que peut supporter le serveur est importante. Il faut toutefois équilibrer ces valeurs avec les capacités de notre serveur (1 CPU et 512 MB de RAM) Dans notre cas, 6 et 12 fonctionnent bien. | ||
+ | • MaxClients est le nombre maximum de requêtes simultanées qui seront traîtées (toute requête supplémentaire sera mise en file d' | ||
+ | • MaxRequestsPerChild est la valeur au-delà de laquelle un serveur enfant se réinitialisera. Par exemple, comme tout logiciel, Apache peut avoir des fuites de mémoire ; ainsi, redémarrer la tâche enfant après un certain nombre de requêtes nettoiera d' | ||
+ | |||
+ | **Disable default site | ||
It is now time to disable the default site, meaning the page which was served when we keyed in the IP address of the server. Basically we want to do this for security and convenience reasons - when somebody keys in the IP address of my server, I'd rather send the user to my web page then the default Apache page. | It is now time to disable the default site, meaning the page which was served when we keyed in the IP address of the server. Basically we want to do this for security and convenience reasons - when somebody keys in the IP address of my server, I'd rather send the user to my web page then the default Apache page. | ||
Ligne 94: | Ligne 160: | ||
• ServerName is the name of your website. | • ServerName is the name of your website. | ||
• DocumentRoot is the path where the files of the web server are stored. | • DocumentRoot is the path where the files of the web server are stored. | ||
- | • ErrorLog defines the path of where error logs are stored. | + | • ErrorLog defines the path of where error logs are stored.** |
- | We have therefore to create the path to these folders: | + | Désactiver le site par défaut |
+ | |||
+ | Il est temps maintenant de désactiver le site par défaut, c' | ||
+ | |||
+ | Il faut d' | ||
+ | |||
+ | Pour le désactiver, | ||
+ | |||
+ | sudo a2dissite 000-default | ||
+ | |||
+ | Vérifiez maintenant le dossier « sites enabled » (sites activés) : le site par défaut n'y est plus ! | ||
+ | |||
+ | Redémarrez le serveur (service apache2 restart) ; pratiquement il n'y a plus de « site » affiché, simplement le dossier d'une arborescence : | ||
+ | |||
+ | Créer notre site | ||
+ | |||
+ | Le nom de notre site sera iceberg-tutorial.com (iceberg.com est déjà pris !) ; nous allons donc créer un fichier de configuration nommé iceberg-tutorial.conf (note : nous aurions pu choisir n' | ||
+ | |||
+ | sudo vi / | ||
+ | |||
+ | Et ajoutez l' | ||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Que signifie tout cela ? | ||
+ | |||
+ | • Apache écoute sur le port 80 (voir ci-dessous). | ||
+ | • Le nom du serveur est celui de notre site. | ||
+ | • DocumentRoot est le chemin de l' | ||
+ | • ErrorLog est le chemin de l' | ||
+ | |||
+ | **We have therefore to create the path to these folders: | ||
sudo mkdir -p / | sudo mkdir -p / | ||
Ligne 128: | Ligne 232: | ||
We can see here that 22 (SSH) and 80 (http) are open – which is expected. | We can see here that 22 (SSH) and 80 (http) are open – which is expected. | ||
- | To scan other port ranges, you can use the -p option (ex: nmap -p 2000-3000 localhost). | + | To scan other port ranges, you can use the -p option (ex: nmap -p 2000-3000 localhost).** |
- | Virtual Sites | + | Nous devons donc créer les chemins vers ces dossiers : |
+ | |||
+ | sudo mkdir -p / | ||
+ | |||
+ | sudo mkdir -p / | ||
+ | |||
+ | Et s' | ||
+ | |||
+ | sudo chmod -R 755 /var/www | ||
+ | |||
+ | Et enfin mettre le site en ligne : | ||
+ | |||
+ | sudo a2ensite iceberg-tutorial.conf | ||
+ | |||
+ | Si nous essayons d' | ||
+ | |||
+ | Par défaut, Apache cherche un fichier nommé index.html – créons-le : | ||
+ | |||
+ | sudo vi / | ||
+ | |||
+ | Tapons par exemple « Hello there » puis fermons et enregistrons. En rafraîchissant la page, vous devriez maintenant voir quelque chose du genre : | ||
+ | |||
+ | Quelques notes rapides sur les ports TCP | ||
+ | |||
+ | Nous avons déjà abordé les ports TCP lors de notre précédent article. Un excellent outil - pour déterminer quels sont les ports ouverts - est nmap. Pour scanner les 1 000 premiers ports, tapez : | ||
+ | |||
+ | sudo nmap localhost | ||
+ | |||
+ | et vous verrez quels sont les ports ouverts. | ||
+ | |||
+ | Ici les ports 22 (SSH) et 80 (http) sont ouverts, comme prévu. | ||
+ | |||
+ | Pour scanner d' | ||
+ | |||
+ | **Virtual Sites | ||
It is possible to host several sites on the same server. Since the server has a unique IP address, the originating URL will help Apache go to the right site - in other words, serve the pages from the correct folder. | It is possible to host several sites on the same server. Since the server has a unique IP address, the originating URL will help Apache go to the right site - in other words, serve the pages from the correct folder. | ||
Ligne 144: | Ligne 282: | ||
... DocumentRoot / | ... DocumentRoot / | ||
- | If the originating URL is www.iceberg-tutorial.com, | + | If the originating URL is www.iceberg-tutorial.com, |
- | Security | + | Sites virtuels |
+ | |||
+ | Il est possible d' | ||
+ | |||
+ | On peut donc avoir plusieurs fichiers de configuration dans le dossier / | ||
+ | |||
+ | Par exemple (souvenons-nous que pour des questions de maintenance, | ||
+ | |||
+ | iceberg-tutorial.conf | ||
+ | ... DocumentRoot / | ||
+ | |||
+ | whatever-site.conf | ||
+ | ... DocumentRoot / | ||
+ | |||
+ | Si l'URL voulu à l' | ||
+ | |||
+ | **Security | ||
What would a web server setup be without security? It would probably be like leaving your car in the garage with the keys on the ignition – somebody may steal the car or not. Maybe it's not a great analogy, but you probably got the point! | What would a web server setup be without security? It would probably be like leaving your car in the garage with the keys on the ignition – somebody may steal the car or not. Maybe it's not a great analogy, but you probably got the point! | ||
Ligne 152: | Ligne 306: | ||
Apache is open source software, therefore it is very easy to add modules and there are a bunch of security modules available. | Apache is open source software, therefore it is very easy to add modules and there are a bunch of security modules available. | ||
- | Remember however that security is not foolproof – it is only a mitigating factor – so you must pro-actively check the system logs for intrusions or attempts of intrusion. Let's make another analogy – it's like you purchased that outstanding vault. Breaking into that vault will be difficult, but if an attacker has enough time and the right skills, he could potentially break inside. Same here – check frequently your system logs (more in the howto article on that). | + | Remember however that security is not foolproof – it is only a mitigating factor – so you must pro-actively check the system logs for intrusions or attempts of intrusion. Let's make another analogy – it's like you purchased that outstanding vault. Breaking into that vault will be difficult, but if an attacker has enough time and the right skills, he could potentially break inside. Same here – check frequently your system logs (more in the howto article on that).** |
+ | |||
+ | Sécurité | ||
+ | |||
+ | À quoi rimerait le paramétrage d'un serveur Web sans sécurité ? | ||
+ | |||
+ | Apache est un logiciel Open Source, il est donc très facile d' | ||
+ | |||
+ | Souvenez-vous toutefois que la sécurité n'est pas à toute épreuve, c'est simplement un facteur limitant ; vous devez donc rechercher activement dans les journaux système des intrusions ou des tentatives d' | ||
- | Out of the box security | + | **Out of the box security |
By “out of the box” is meant that no download is required – just add all below to the end of the file / | By “out of the box” is meant that no download is required – just add all below to the end of the file / | ||
Ligne 186: | Ligne 348: | ||
• TraceEnabled doesn' | • TraceEnabled doesn' | ||
• The Directory directive adds restrictions on root folder. | • The Directory directive adds restrictions on root folder. | ||
- | • As explained earlier, Apache can easily be enhanced with modules. Here we ask Apache to load the headers_module, | + | • As explained earlier, Apache can easily be enhanced with modules. Here we ask Apache to load the headers_module, |
- | Additional security – module ModSecurity for Apache | + | Sécurité par défaut |
+ | |||
+ | Par « par défaut » j' | ||
+ | |||
+ | ServerTokens Prod | ||
+ | ServerSignature Off | ||
+ | |||
+ | FileETag None | ||
+ | TraceEnable off | ||
+ | Timeout 60 | ||
+ | |||
+ | < | ||
+ | Options None | ||
+ | AllowOverride None | ||
+ | Order deny, | ||
+ | |||
+ | < | ||
+ | deny from all | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | LoadModule headers_module / | ||
+ | |||
+ | Header edit Set-Cookie ^(.*)$ $1; | ||
+ | |||
+ | Header always append X-Frame-Options SAMEORIGIN | ||
+ | |||
+ | Commentaire rapide sur la signification de tout cela : | ||
+ | • ServerTokens et ServerSignature ne donneront pas la version d' | ||
+ | • TraceEnabled ne permet pas le débogage (une trace additionnelle) et TimeOut est sans doute explicite ! | ||
+ | • Les ordres concernant le Directory (répertoire) ajoutent des restrictions sur le dossier racine. | ||
+ | • Comme expliqué plus haut, on peut facilement améliorer Apache avec des modules. Ici nous demandons à Apache de charger le module headers qui sera utilisé dans deux commandes ci-dessous. (Header Edits… et Header always…) de façon à bloquer des attaques de type XSS ou utilisant iFrames. Je ne suis pas spécialiste de ces sujets, ma recommandation serait de copier-coller dans Google la ligne entière (Header Edits… et Header always…) pour plus de détails. | ||
+ | |||
+ | **Additional security – module ModSecurity for Apache | ||
Extremely popular for Apache servers (and maybe others), ModSecurity is a must-have module. Note this is not mandatory, however I highly recommend installing it (it's free and it adds security – so why not?). | Extremely popular for Apache servers (and maybe others), ModSecurity is a must-have module. Note this is not mandatory, however I highly recommend installing it (it's free and it adds security – so why not?). | ||
Ligne 194: | Ligne 389: | ||
Once ModSecurity is installed, it doesn' | Once ModSecurity is installed, it doesn' | ||
- | There are many websites with all the instructions on how to install ModSecurity and turn on CRS – for all step-by-step instructions, | + | There are many websites with all the instructions on how to install ModSecurity and turn on CRS – for all step-by-step instructions, |
- | Cleanup and some statistics | + | Sécurité supplémentaire – module ModSecurity pour Apache |
+ | |||
+ | Très courant pour les serveurs Apache (et peut-être pour d' | ||
+ | |||
+ | Une fois installé, ModSecurity ne fait rien par défaut, vous devez activer les options dont vous avez besoin. Pour faciliter les choses, des règles communes (appelées aussi CRS – Core Set Rules, ensemble des règles de base) sont disponibles et ont juste besoin d' | ||
+ | |||
+ | Il y a un tas de sites Internet donnant les instructions d' | ||
+ | |||
+ | **Cleanup and some statistics | ||
The folder / | The folder / | ||
Ligne 204: | Ligne 407: | ||
We can now also run statistics – what pages were open, IP source, browser info, … etc. Of course, you can use Google analytics; however as a pure geek, I personally enjoyed browsing the web logs to get my own stats. | We can now also run statistics – what pages were open, IP source, browser info, … etc. Of course, you can use Google analytics; however as a pure geek, I personally enjoyed browsing the web logs to get my own stats. | ||
- | Note that the log file size will continue increasing – so we must clean it up. This very small script (shown on the next page)will count all unique access to the web server and then compress the log. It's a bash job, all lines starting with # are comments. Once the script is created, you can add the script to a cron job to run daily: | + | Note that the log file size will continue increasing – so we must clean it up. This very small script (shown on the next page)will count all unique access to the web server and then compress the log. It's a bash job, all lines starting with # are comments. Once the script is created, you can add the script to a cron job to run daily:** |
- | Final Note – website registration and DNS | + | Nettoyage et quelques statistiques |
+ | |||
+ | Le dossier / | ||
+ | |||
+ | Allez voir dans access.log. Vous y verrez l' | ||
+ | |||
+ | Nous pouvons aussi obtenir des statistiques : quelles pages ont été ouvertes, l'IP de la source, des informations sur le navigateur, etc. Vous pouvez bien sûr utiliser Google Analytics ; | ||
+ | |||
+ | Remarquez que la taille des fichiers journaux n' | ||
+ | |||
+ | **Final Note – website registration and DNS | ||
Once the web server is set up and pages ready, you will probably register a website name – it is easier to remember www.iceberg-tutorial.com rather than 159.203.90.111. | Once the web server is set up and pages ready, you will probably register a website name – it is easier to remember www.iceberg-tutorial.com rather than 159.203.90.111. | ||
Ligne 216: | Ligne 429: | ||
All information on theses steps is very well explained here: https:// | All information on theses steps is very well explained here: https:// | ||
- | I hope you have enjoyed these articles and that you will create your own website, from scratch! | + | I hope you have enjoyed these articles and that you will create your own website, from scratch!** |
+ | |||
+ | Note finale – Enregistrement du site et DNS | ||
+ | |||
+ | Une fois que le serveur est monté et que les pages sont prêtes, vous allez probablement enregistrer un nom de site ; il est plus facile de se souvenir de iceberg-tutorial.com que de 159.203.90.111. | ||
+ | |||
+ | Pour faire cela, allez sur votre registrar en ligne favori et suivez toutes les étapes (il faudra payer quelque chose, c'est habituellement de l' | ||
+ | |||
+ | Vous devrez alors créer une entrée DNS à Digital Ocean, c'est le lien qui détermine où doit aller le navigateur quand quelqu' | ||
+ | |||
+ | Toutes les informations sur ces étapes sont très bien expliquées ici : https:// | ||
+ | |||
+ | J' |
issue102/tutoriel_2.1446400503.txt.gz · Dernière modification : 2015/11/01 18:55 de auntiee