Débutant120 min80 XP
Objectifs de cette leçon
- Installer et configurer nginx
- Déployer une application Node.js
- Configurer PM2 pour la production
- Automatiser le démarrage au boot
Projet : Configuration serveur complet 🏆
Objectif
Configurer un serveur Linux pour déployer une app Node.js avec nginx, pm2, et HTTPS.
Étape 1 : Préparer le serveur
sudo apt update && sudo apt upgrade -y sudo apt install -y git curl htop tree ufw sudo ufw allow OpenSSH sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw enable
Étape 2 : Installer Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash nvm install 20 && nvm use 20
Étape 3 : nginx
sudo apt install -y nginx
server { listen 80; server_name mondomaine.com; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; } }
sudo ln -s /etc/nginx/sites-available/monapp /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl restart nginx
Étape 4 : Déployer l'application
cd /var/www && git clone https://github.com/monuser/monapp.git cd monapp && npm install cp .env.example .env pm2 start server.js --name "monapp" pm2 save && pm2 startup
Étape 5 : HTTPS
sudo apt install -y certbot python3-certbot-nginx sudo certbot --nginx -d mondomaine.com sudo certbot renew --dry-run
Checklist finale
| Étape | Statut |
|---|---|
| Serveur à jour | ✅ |
| Pare-feu configuré | ✅ |
| Node.js installé | ✅ |
| nginx configuré | ✅ |
| Application déployée | ✅ |
| pm2 + démarrage auto | ✅ |
| HTTPS activé | ✅ |
Extensions possibles
- Monitoring : Grafana + Prometheus
- CI/CD : GitHub Actions
- Backups : Script cron
- Logs : ELK Stack ou Loki
🎉 Félicitations ! Tu maîtrises les bases de l'administration Linux.
⚡ Simulateur — Projet : Configuration serveur
Étape 1/8📝 Pseudo-code
1sudo apt update && sudo apt install nginx -y
2sudo nano /etc/nginx/sites-available/monsite
3sudo ln -s /etc/nginx/sites-available/monsite /etc/nginx/sites-enabled/
4sudo nginx -t
5sudo systemctl restart nginx
6pm2 start server.js --name monsite
7pm2 save
8pm2 startup
⚙️ Exécution
📦 Mémoire
etape
Installation
🔀 Flux d'exécution
apt install nginx
📟 Console
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Reading package lists... Done
Building dependency tree
The following NEW packages will be installed: nginx
0 upgraded, 1 newly installed, 0 to remove.
Setting up nginx (1.24.0-1) ...
3
Installation de Nginx
apt update met à jour la liste des paquets, apt install nginx -y installe nginx sans demander de confirmation. -y = yes à tout.