**Motivations:** - Fix 401 error on anchorage API due to .env not being loaded correctly - Fix 502 error on dashboard due to service not running - Add backup script for mining keys and wallet descriptors - Improve service management with startup scripts and systemd services **Root causes:** - dotenv.config() was called without explicit path, causing .env to be loaded from wrong directory - Services were not started automatically, causing 502 errors - No backup mechanism for critical keys and wallet data **Correctifs:** - Improved .env loading in api-anchorage/src/server.js with explicit path - Improved .env loading in signet-dashboard/src/server.js with explicit path - Added backups/ directory to .gitignore to prevent committing sensitive data - Created export-backup.sh script for backing up mining keys and wallet descriptors **Evolutions:** - Added api-anchorage/start.sh script for proper service startup - Added api-anchorage/anchorage-api.service systemd service file - Added fixKnowledge/api-anchorage-401-error.md documentation - Added fixKnowledge/dashboard-502-error.md documentation - Updated mempool submodule **Pages affectées:** - .gitignore (added backups/) - api-anchorage/src/server.js (improved .env loading) - api-anchorage/start.sh (new) - api-anchorage/anchorage-api.service (new) - signet-dashboard/src/server.js (improved .env loading) - export-backup.sh (new) - fixKnowledge/api-anchorage-401-error.md (new) - fixKnowledge/dashboard-502-error.md (new) - mempool (submodule updated)
196 lines
5.0 KiB
Markdown
196 lines
5.0 KiB
Markdown
# Correction : Erreur 502 Bad Gateway sur dashboard.certificator.4nkweb.com
|
|
|
|
**Auteur** : Équipe 4NK
|
|
**Date** : 2026-01-24
|
|
**Version** : 1.0
|
|
|
|
## Problème Identifié
|
|
|
|
Le dashboard retournait une erreur 502 Bad Gateway sur `https://dashboard.certificator.4nkweb.com/`.
|
|
|
|
### Symptômes
|
|
|
|
- Erreur 502 Bad Gateway lors de l'accès au dashboard
|
|
- Le proxy nginx ne peut pas se connecter au backend
|
|
- Le dashboard n'était pas en cours d'exécution
|
|
|
|
## Cause Racine
|
|
|
|
Le dashboard n'était pas démarré. Le processus Node.js n'était pas en cours d'exécution sur le port 3020, ce qui causait l'erreur 502 Bad Gateway lorsque nginx essayait de se connecter au backend.
|
|
|
|
**Problème technique** : Le dashboard n'était pas démarré automatiquement et nécessitait un démarrage manuel.
|
|
|
|
## Correctifs Appliqués
|
|
|
|
### 1. Amélioration du chargement du `.env` dans `server.js`
|
|
|
|
**Fichier** : `signet-dashboard/src/server.js`
|
|
|
|
**Avant** :
|
|
```javascript
|
|
import dotenv from 'dotenv';
|
|
// ...
|
|
dotenv.config();
|
|
```
|
|
|
|
**Après** :
|
|
```javascript
|
|
import dotenv from 'dotenv';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
|
|
// Get the directory of the current module
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
// Charger les variables d'environnement depuis le répertoire racine du projet signet-dashboard
|
|
// Cela garantit que le .env est chargé même si le script est exécuté depuis un autre répertoire
|
|
const envPath = join(__dirname, '../.env');
|
|
dotenv.config({ path: envPath });
|
|
```
|
|
|
|
**Impact** : Le `.env` est maintenant chargé depuis un chemin explicite, garantissant que le bon fichier est utilisé même si le script est exécuté depuis un autre répertoire.
|
|
|
|
### 2. Démarrage du dashboard
|
|
|
|
Le dashboard a été démarré avec :
|
|
```bash
|
|
cd signet-dashboard
|
|
npm start
|
|
```
|
|
|
|
## Modifications
|
|
|
|
### Fichiers Modifiés
|
|
|
|
- `signet-dashboard/src/server.js` : Amélioration du chargement du `.env` avec chemin explicite
|
|
|
|
### Fichiers Créés
|
|
|
|
- `fixKnowledge/dashboard-502-error.md` : Cette documentation
|
|
|
|
## Modalités de Déploiement
|
|
|
|
### Démarrage du Dashboard
|
|
|
|
1. **Vérifier que le port est libre** :
|
|
```bash
|
|
sudo lsof -i :3020
|
|
```
|
|
|
|
2. **Démarrer le dashboard** :
|
|
```bash
|
|
cd /home/ncantu/Bureau/code/bitcoin/signet-dashboard
|
|
npm start
|
|
# Ou utiliser le script de démarrage
|
|
./start.sh
|
|
```
|
|
|
|
3. **Démarrer en arrière-plan** :
|
|
```bash
|
|
cd /home/ncantu/Bureau/code/bitcoin/signet-dashboard
|
|
nohup npm start > /tmp/dashboard.log 2>&1 &
|
|
```
|
|
|
|
### Installation d'un service systemd (recommandé)
|
|
|
|
Pour éviter que le dashboard ne s'arrête, créer un service systemd :
|
|
|
|
1. **Créer le fichier de service** :
|
|
```bash
|
|
sudo nano /etc/systemd/system/signet-dashboard.service
|
|
```
|
|
|
|
2. **Contenu du service** :
|
|
```ini
|
|
[Unit]
|
|
Description=Bitcoin Signet Dashboard
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=ncantu
|
|
WorkingDirectory=/home/ncantu/Bureau/code/bitcoin/signet-dashboard
|
|
Environment=NODE_ENV=production
|
|
ExecStart=/usr/bin/node /home/ncantu/Bureau/code/bitcoin/signet-dashboard/src/server.js
|
|
Restart=always
|
|
RestartSec=10
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
```
|
|
|
|
3. **Activer et démarrer le service** :
|
|
```bash
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable signet-dashboard
|
|
sudo systemctl start signet-dashboard
|
|
```
|
|
|
|
4. **Vérifier le statut** :
|
|
```bash
|
|
sudo systemctl status signet-dashboard
|
|
```
|
|
|
|
## Modalités d'Analyse
|
|
|
|
### Vérification que le dashboard fonctionne
|
|
|
|
1. **Test de l'API** :
|
|
```bash
|
|
curl http://localhost:3020/api/blockchain/info
|
|
```
|
|
|
|
2. **Test de l'interface web** :
|
|
```bash
|
|
curl http://localhost:3020/
|
|
```
|
|
|
|
3. **Vérifier les logs** :
|
|
```bash
|
|
# Si démarré avec npm start
|
|
tail -f /tmp/dashboard.log
|
|
|
|
# Si démarré avec systemd
|
|
sudo journalctl -u signet-dashboard -f
|
|
```
|
|
|
|
### Vérification de la connexion nginx
|
|
|
|
1. **Vérifier que nginx peut se connecter** :
|
|
```bash
|
|
# Depuis le serveur proxy (192.168.1.100)
|
|
curl http://192.168.1.105:3020/api/blockchain/info
|
|
```
|
|
|
|
2. **Vérifier les logs nginx** :
|
|
```bash
|
|
# Sur le serveur proxy
|
|
sudo tail -f /var/log/nginx/dashboard.certificator.4nkweb.com.error.log
|
|
```
|
|
|
|
## Résultat
|
|
|
|
✅ **Problème résolu**
|
|
|
|
- Le dashboard est maintenant démarré et écoute sur le port 3020
|
|
- L'API répond correctement (888 blocs détectés)
|
|
- Le dashboard est accessible via `https://dashboard.certificator.4nkweb.com/`
|
|
- Le chargement du `.env` est maintenant explicite et fiable
|
|
|
|
## Prévention
|
|
|
|
Pour éviter ce problème à l'avenir :
|
|
|
|
1. **Utiliser un service systemd ou PM2** pour gérer le dashboard et faciliter les redémarrages
|
|
2. **Configurer le démarrage automatique** au boot du système
|
|
3. **Surveiller les logs** pour détecter les arrêts inattendus
|
|
4. **Utiliser un chemin explicite pour le `.env`** dans les applications Node.js
|
|
|
|
## Pages Affectées
|
|
|
|
- `signet-dashboard/src/server.js` : Amélioration du chargement du `.env`
|
|
- `fixKnowledge/dashboard-502-error.md` : Documentation (nouveau)
|