
Some checks failed
CI - 4NK_node / Code Quality (push) Failing after 50s
CI - 4NK_node / Unit Tests (push) Failing after 29s
CI - 4NK_node / Integration Tests (push) Failing after 12s
CI - 4NK_node / Security Tests (push) Failing after 27s
CI - 4NK_node / Docker Build & Test (push) Failing after 9s
CI - 4NK_node / Documentation Tests (push) Failing after 4s
CI - 4NK_node / Security Audit (push) Successful in 3s
CI - 4NK_node / Release Guard (push) Has been skipped
CI - 4NK_node / Performance Tests (push) Successful in 28s
CI - 4NK_node / Notify (push) Failing after 2s
CI - 4NK_node / Publish Release (push) Has been skipped
254 lines
6.0 KiB
Markdown
254 lines
6.0 KiB
Markdown
# Configuration Nginx sur l'hôte Debian pour 4NK_node
|
|
|
|
## Vue d'ensemble
|
|
|
|
Cette configuration installe Nginx directement sur l'hôte Debian pour servir de reverse proxy vers tous les services Docker 4NK_node. Cela permet d'avoir un point d'entrée unique et une meilleure gestion des accès.
|
|
|
|
## Architecture
|
|
|
|
```
|
|
Internet/Client → Nginx (hôte:80) → Services Docker 4NK_node
|
|
```
|
|
|
|
## Services exposés via Nginx
|
|
|
|
| Route | Service | Port Docker | Description |
|
|
|-------|---------|-------------|-------------|
|
|
| `/` | IHM Client Web | 3003 | Interface principale React |
|
|
| `/bitcoin/rpc/` | Bitcoin Core | 38332 | API JSON-RPC Bitcoin |
|
|
| `/bitcoin/p2p/` | Bitcoin Core | 38333 | Port P2P Bitcoin |
|
|
| `/blindbit/` | BlindBit | 8000 | API BlindBit |
|
|
| `/storage/` | SDK Storage | 8081 | API de stockage |
|
|
| `/relay1/` | SDK Relay 1 | 8090 | API Relay 1 |
|
|
| `/relay2/` | SDK Relay 2 | 8092 | API Relay 2 |
|
|
| `/relay3/` | SDK Relay 3 | 8094 | API Relay 3 |
|
|
| `/signer/` | SDK Signer | 9090 | API de signature |
|
|
| `/ihm/` | IHM Client | 3003 | Interface web |
|
|
| `/ihm-http/` | IHM Client | 8080 | Interface HTTP |
|
|
| `/grafana/` | Grafana | 3000 | Dashboard de monitoring |
|
|
| `/loki/` | Loki | 3100 | API de logs |
|
|
|
|
## Installation
|
|
|
|
### Prérequis
|
|
|
|
- Debian avec accès root/sudo
|
|
- Services Docker 4NK_node démarrés
|
|
- Port 80 disponible
|
|
|
|
### Installation automatique
|
|
|
|
```bash
|
|
cd 4NK_dev/4NK_node/conf
|
|
sudo ./install-nginx-host.sh
|
|
```
|
|
|
|
### Installation manuelle
|
|
|
|
1. **Installer Nginx**
|
|
```bash
|
|
sudo apt update
|
|
sudo apt install -y nginx
|
|
```
|
|
|
|
2. **Configurer les logs**
|
|
```bash
|
|
sudo mkdir -p /var/log/nginx/4nk-node
|
|
sudo chown www-data:www-data /var/log/nginx/4nk-node
|
|
```
|
|
|
|
3. **Installer la configuration**
|
|
```bash
|
|
sudo cp nginx.conf /etc/nginx/nginx.conf
|
|
sudo nginx -t
|
|
sudo systemctl restart nginx
|
|
sudo systemctl enable nginx
|
|
```
|
|
|
|
## Configuration
|
|
|
|
### Fichier principal
|
|
|
|
- **Fichier**: `conf/nginx.conf`
|
|
- **Emplacement système**: `/etc/nginx/nginx.conf`
|
|
|
|
### Caractéristiques
|
|
|
|
- **Rate limiting**: 10 req/s pour les APIs, 1 req/s pour les connexions
|
|
- **Gzip compression**: Optimisé pour les réponses HTTP
|
|
- **Security headers**: Protection XSS, CSRF, etc.
|
|
- **WebSocket support**: Pour les services temps réel
|
|
- **Health check**: Endpoint `/health` pour la surveillance
|
|
|
|
### Logs
|
|
|
|
- **Accès**: `/var/log/nginx/4nk-node-access.log`
|
|
- **Erreurs**: `/var/log/nginx/4nk-node-error.log`
|
|
- **Format**: Logs détaillés avec upstream information
|
|
|
|
## Utilisation
|
|
|
|
### Test de connectivité
|
|
|
|
```bash
|
|
# Test du health check
|
|
curl http://localhost/health
|
|
|
|
# Test Bitcoin RPC
|
|
curl -X POST http://localhost/bitcoin/rpc/ \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"jsonrpc": "1.0", "id": "test", "method": "getblockchaininfo", "params": []}'
|
|
|
|
# Test BlindBit
|
|
curl http://localhost/blindbit/health
|
|
```
|
|
|
|
### Monitoring
|
|
|
|
```bash
|
|
# Statut du service
|
|
sudo systemctl status nginx
|
|
|
|
# Logs en temps réel
|
|
sudo tail -f /var/log/nginx/4nk-node-access.log
|
|
|
|
# Logs d'erreurs
|
|
sudo tail -f /var/log/nginx/4nk-node-error.log
|
|
```
|
|
|
|
## Sécurité
|
|
|
|
### Headers de sécurité
|
|
|
|
- `X-Frame-Options: SAMEORIGIN`
|
|
- `X-XSS-Protection: 1; mode=block`
|
|
- `X-Content-Type-Options: nosniff`
|
|
- `Referrer-Policy: no-referrer-when-downgrade`
|
|
- `Content-Security-Policy: default-src 'self' http: https: data: blob: 'unsafe-inline'`
|
|
|
|
### Rate Limiting
|
|
|
|
- **APIs**: 10 requêtes par seconde avec burst de 20
|
|
- **Connexions**: 1 requête par seconde avec burst de 5
|
|
|
|
### Accès réseau
|
|
|
|
- **Écoute**: Port 80 sur toutes les interfaces
|
|
- **Upstream**: Connexions locales vers les ports Docker exposés
|
|
|
|
## Dépannage
|
|
|
|
### Problèmes courants
|
|
|
|
1. **Port 80 déjà utilisé**
|
|
```bash
|
|
sudo netstat -tlnp | grep :80
|
|
sudo systemctl stop apache2 # Si Apache est installé
|
|
```
|
|
|
|
2. **Configuration invalide**
|
|
```bash
|
|
sudo nginx -t
|
|
sudo nginx -T | grep -A 10 -B 10 "error"
|
|
```
|
|
|
|
3. **Permissions de logs**
|
|
```bash
|
|
sudo chown -R www-data:www-data /var/log/nginx/4nk-node
|
|
sudo chmod 755 /var/log/nginx/4nk-node
|
|
```
|
|
|
|
4. **Services Docker non accessibles**
|
|
```bash
|
|
# Vérifier que les services écoutent
|
|
sudo netstat -tlnp | grep -E "(38332|8000|8081|8090|9090|3003)"
|
|
|
|
# Vérifier les conteneurs Docker
|
|
docker ps
|
|
```
|
|
|
|
### Logs de débogage
|
|
|
|
```bash
|
|
# Activer le mode debug temporairement
|
|
sudo nginx -g "error_log /var/log/nginx/debug.log debug;"
|
|
|
|
# Redémarrer et vérifier
|
|
sudo systemctl restart nginx
|
|
sudo tail -f /var/log/nginx/debug.log
|
|
```
|
|
|
|
## Maintenance
|
|
|
|
### Mise à jour de la configuration
|
|
|
|
```bash
|
|
# Sauvegarder l'ancienne
|
|
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup.$(date +%Y%m%d_%H%M%S)
|
|
|
|
# Installer la nouvelle
|
|
sudo cp nginx.conf /etc/nginx/nginx.conf
|
|
|
|
# Tester et redémarrer
|
|
sudo nginx -t && sudo systemctl reload nginx
|
|
```
|
|
|
|
### Rotation des logs
|
|
|
|
```bash
|
|
# Créer un script de rotation personnalisé
|
|
sudo tee /etc/logrotate.d/4nk-node-nginx << EOF
|
|
/var/log/nginx/4nk-node-*.log {
|
|
daily
|
|
missingok
|
|
rotate 52
|
|
compress
|
|
delaycompress
|
|
notifempty
|
|
create 644 www-data www-data
|
|
postrotate
|
|
systemctl reload nginx
|
|
endscript
|
|
}
|
|
EOF
|
|
```
|
|
|
|
## Intégration avec le monitoring
|
|
|
|
### Grafana
|
|
|
|
- **URL**: `http://localhost/grafana/`
|
|
- **Datasource**: Loki configuré automatiquement
|
|
- **Dashboard**: 4NK Node Overview disponible
|
|
|
|
### Loki
|
|
|
|
- **URL**: `http://localhost/loki/`
|
|
- **Logs Nginx**: Intégrés via Promtail
|
|
- **Requêtes**: LogQL pour analyser les accès
|
|
|
|
## Support et développement
|
|
|
|
### Ajout de nouveaux services
|
|
|
|
1. Ajouter l'upstream dans la section `upstream`
|
|
2. Créer la location block correspondante
|
|
3. Tester la configuration : `sudo nginx -t`
|
|
4. Recharger : `sudo systemctl reload nginx`
|
|
|
|
### Configuration HTTPS
|
|
|
|
1. Obtenir les certificats SSL
|
|
2. Décommenter la section HTTPS dans `nginx.conf`
|
|
3. Configurer les chemins des certificats
|
|
4. Redémarrer Nginx
|
|
|
|
### Performance
|
|
|
|
- **Worker processes**: Auto-détection du nombre de CPU
|
|
- **Keepalive**: 32 connexions par upstream
|
|
- **Buffer sizes**: Optimisés pour les APIs
|
|
- **Timeouts**: 30s pour les APIs lentes (Bitcoin, BlindBit)
|
|
|
|
|