====== Installation d'un Serveur Web (Apache/Nginx) ====== ===== 1. Introduction ===== //Inspiré de [[https://www.it-connect.fr/installer-un-serveur-web-debian/|IT-Connect]] et [[https://wiki.debian.org/fr/WebServer|Wiki Debian]]// Choix des technologies : | **Solution** | **Cas d'usage** | |------------|----------------| | {{:wiki:apache-logo.png?50|Apache}} Apache | Applications traditionnelles, .htaccess | | {{:wiki:nginx-logo.png?50|Nginx}} Nginx | Hautes performances, reverse proxy | ===== 2. Installation d'Apache ===== === 2.1. Installation de base === sudo apt update sudo apt install apache2 apache2-utils === 2.2. Configuration essentielle === **Structure des fichiers** : | Chemin | Description | |--------|-------------| | `/etc/apache2/apache2.conf` | Fichier de config principal | | `/etc/apache2/sites-available/` | Sites virtuels | | `/var/www/html/` | Racine web par défaut | **Activer un site** : sudo a2ensite mon-site.conf sudo systemctl reload apache2 === 2.3. Optimisation (IT-Connect) === StartServers 4 MinSpareServers 3 MaxSpareServers 10 MaxRequestWorkers 150 MaxConnectionsPerChild 3000 ===== 3. Installation de Nginx ===== === 3.1. Installation === sudo apt install nginx === 3.2. Configuration clé === **Fichiers importants** : | Chemin | Description | |--------|-------------| | `/etc/nginx/nginx.conf` | Config globale | | `/etc/nginx/sites-available/` | Sites virtuels | **Exemple de config** : server { listen 80; server_name mondomaine.com; root /var/www/mon-site; index index.html; location / { try_files $uri $uri/ =404; } } ===== 4. Sécurité ===== === 4.1. Pare-feu === sudo ufw allow 'Apache Full' # Apache sudo ufw allow 'Nginx HTTP' # Nginx === 4.2. Hardening === **Pour Apache** : sudo a2dismod autoindex sudo systemctl restart apache2 **Pour Nginx** : server_tokens off; ===== 5. PHP & Bases de données ===== === 5.1. PHP-FPM === sudo apt install php-fpm php-mysql === 5.2. Intégration === **Avec Nginx** : location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.2-fpm.sock; } ===== 6. Monitoring ===== === 6.1. Commandes utiles === | **Action** | **Commande** | |------------|--------------| | Vérifier syntaxe Apache | `sudo apache2ctl configtest` | | Vérifier syntaxe Nginx | `sudo nginx -t` | | Voir les logs | `sudo tail -f /var/log/apache2/error.log` | ===== 7. Documentation ===== * [[https://www.it-connect.fr/installer-un-serveur-web-debian/|IT-Connect : Serveur Web sous Debian]] * [[https://httpd.apache.org/docs/2.4/fr/|Docs Apache]] * [[https://nginx.org/en/docs/|Docs Nginx]] ✓ Toujours mettre à jour les paquets (`sudo apt upgrade`) ✓ Utiliser Let's Encrypt pour HTTPS ✓ Sauvegarder les fichiers de config Pour tester les performances : ab -n 1000 -c 100 http://localhost/