**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)
5.0 KiB
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 :
import dotenv from 'dotenv';
// ...
dotenv.config();
Après :
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 :
cd signet-dashboard
npm start
Modifications
Fichiers Modifiés
signet-dashboard/src/server.js: Amélioration du chargement du.envavec chemin explicite
Fichiers Créés
fixKnowledge/dashboard-502-error.md: Cette documentation
Modalités de Déploiement
Démarrage du Dashboard
-
Vérifier que le port est libre :
sudo lsof -i :3020 -
Démarrer le dashboard :
cd /home/ncantu/Bureau/code/bitcoin/signet-dashboard npm start # Ou utiliser le script de démarrage ./start.sh -
Démarrer en arrière-plan :
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 :
-
Créer le fichier de service :
sudo nano /etc/systemd/system/signet-dashboard.service -
Contenu du service :
[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 -
Activer et démarrer le service :
sudo systemctl daemon-reload sudo systemctl enable signet-dashboard sudo systemctl start signet-dashboard -
Vérifier le statut :
sudo systemctl status signet-dashboard
Modalités d'Analyse
Vérification que le dashboard fonctionne
-
Test de l'API :
curl http://localhost:3020/api/blockchain/info -
Test de l'interface web :
curl http://localhost:3020/ -
Vérifier les logs :
# 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
-
Vérifier que nginx peut se connecter :
# Depuis le serveur proxy (192.168.1.100) curl http://192.168.1.105:3020/api/blockchain/info -
Vérifier les logs nginx :
# 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
.envest maintenant explicite et fiable
Prévention
Pour éviter ce problème à l'avenir :
- Utiliser un service systemd ou PM2 pour gérer le dashboard et faciliter les redémarrages
- Configurer le démarrage automatique au boot du système
- Surveiller les logs pour détecter les arrêts inattendus
- Utiliser un chemin explicite pour le
.envdans les applications Node.js
Pages Affectées
signet-dashboard/src/server.js: Amélioration du chargement du.envfixKnowledge/dashboard-502-error.md: Documentation (nouveau)