2026-01-23 23:23:21 +04:00
|
|
|
# Deploiement Backend Directus
|
|
|
|
|
|
|
|
|
|
Guide de deploiement du backend Directus sur un serveur Ubuntu.
|
|
|
|
|
|
|
|
|
|
## Prerequis
|
|
|
|
|
|
|
|
|
|
- Ubuntu 20.04+ / Debian 11+
|
|
|
|
|
- Acces root ou sudo
|
|
|
|
|
- Docker (ou Node.js 22+ pour une installation sans Docker)
|
|
|
|
|
- Nom de domaine configure (ex: `api.exemple.com`)
|
|
|
|
|
|
|
|
|
|
## 1. Installation des dependances
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo apt update && sudo apt upgrade -y
|
|
|
|
|
|
|
|
|
|
# Docker
|
|
|
|
|
sudo apt install -y docker.io docker-compose-v2
|
|
|
|
|
sudo usermod -aG docker $USER
|
|
|
|
|
newgrp docker
|
|
|
|
|
|
|
|
|
|
# Nginx et Certbot
|
|
|
|
|
sudo apt install -y nginx certbot python3-certbot-nginx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2. Configuration du projet
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Cloner le projet
|
|
|
|
|
git clone <URL_DU_REPO> backend
|
|
|
|
|
cd backend
|
|
|
|
|
|
|
|
|
|
# Configurer l'environnement
|
|
|
|
|
cp .env.sample .env
|
|
|
|
|
nano .env
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Variables a modifier dans `.env`:
|
|
|
|
|
|
|
|
|
|
```env
|
|
|
|
|
PUBLIC_URL="https://api.exemple.com"
|
|
|
|
|
KEY="<openssl rand -hex 32>"
|
|
|
|
|
SECRET="<openssl rand -hex 32>"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 3. Preparation des volumes
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
mkdir -p database uploads extensions
|
|
|
|
|
chmod 755 database uploads extensions
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4. Demarrage de Directus
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker compose up -d
|
|
|
|
|
docker compose ps
|
|
|
|
|
curl http://localhost:8055/server/health
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 5. Configuration Nginx
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo nano /etc/nginx/sites-available/api.exemple.com
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```nginx
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
listen [::]:80;
|
|
|
|
|
server_name api.exemple.com;
|
|
|
|
|
|
|
|
|
|
client_max_body_size 100M;
|
|
|
|
|
|
|
|
|
|
access_log /var/log/nginx/api.exemple.com.access.log;
|
|
|
|
|
error_log /var/log/nginx/api.exemple.com.error.log;
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
proxy_pass http://127.0.0.1:8055;
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
proxy_set_header Connection 'upgrade';
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
proxy_cache_bypass $http_upgrade;
|
|
|
|
|
proxy_connect_timeout 600;
|
|
|
|
|
proxy_send_timeout 600;
|
|
|
|
|
proxy_read_timeout 600;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location /websocket {
|
2026-01-24 17:58:00 +04:00
|
|
|
proxy_pass http://127.0.0.1:8055/websocket;
|
2026-01-23 23:23:21 +04:00
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
proxy_set_header Connection "Upgrade";
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2026-01-24 17:58:00 +04:00
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
proxy_read_timeout 86400;
|
2026-01-23 23:23:21 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Activer le site:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo ln -s /etc/nginx/sites-available/api.exemple.com /etc/nginx/sites-enabled/
|
|
|
|
|
sudo nginx -t && sudo systemctl reload nginx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 6. Certificat SSL
|
|
|
|
|
|
|
|
|
|
Verifier le DNS:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
dig +short api.exemple.com
|
|
|
|
|
curl -4 ifconfig.me
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Obtenir le certificat:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo certbot --nginx -d api.exemple.com
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 7. Verification
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
curl https://api.exemple.com/server/health
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Acces admin: `https://api.exemple.com/admin`
|
|
|
|
|
|
|
|
|
|
## Commandes utiles
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Logs
|
|
|
|
|
docker compose logs -f
|
|
|
|
|
|
|
|
|
|
# Redemarrer
|
|
|
|
|
docker compose restart
|
|
|
|
|
|
|
|
|
|
# Mise a jour
|
|
|
|
|
git pull origin main
|
|
|
|
|
docker compose down && docker compose up -d
|
|
|
|
|
|
|
|
|
|
# Backup base de donnees
|
|
|
|
|
cp database/data.db database/data.db.backup-$(date +%Y%m%d)
|
|
|
|
|
|
|
|
|
|
# Backup uploads
|
|
|
|
|
tar -czf uploads-backup-$(date +%Y%m%d).tar.gz uploads/
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Troubleshooting
|
|
|
|
|
|
|
|
|
|
### Erreur 502
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker compose ps
|
|
|
|
|
curl http://localhost:8055/server/health
|
|
|
|
|
sudo tail -20 /var/log/nginx/api.exemple.com.error.log
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Erreur SSL
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
dig +short api.exemple.com
|
|
|
|
|
sudo certbot certificates
|
|
|
|
|
sudo certbot renew --force-renewal
|
|
|
|
|
```
|