V0.5.0.1
This commit is contained in:
1 parent
aaec7e8d0f
commit
bc9c88a548
6 files changed
+278
-6
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
# Configuration Supabase (indispensable au moment du build Next.js)
|
||||||
|
NEXT_PUBLIC_SUPABASE_URL=https://votre-projet.supabase.co
|
||||||
|
NEXT_PUBLIC_SUPABASE_ANON_KEY=votre-cle-anon-supabase
|
||||||
|
|
||||||
|
# Configuration Serveur
|
||||||
|
PORT=3000
|
||||||
|
NODE_ENV=production
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
# Guide de Déploiement en Production — TER Ferrovia Régional
|
||||||
|
|
||||||
|
Ce guide détaille la procédure complète pour déployer et maintenir l'application Next.js avec **PM2** et **Nginx** sur le nom de domaine **`ter-ferrovia.mrpatator.fr`**.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Prérequis sur le serveur (Ubuntu / Debian / Linux)
|
||||||
|
|
||||||
|
Installez Node.js (v20+), PM2, Nginx et Certbot :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Mise à jour du système
|
||||||
|
sudo apt update && sudo apt upgrade -y
|
||||||
|
|
||||||
|
# Installation de Node.js 20 LTS
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||||
|
sudo apt install -y nodejs nginx certbot python3-certbot-nginx
|
||||||
|
|
||||||
|
# Installation globale de PM2
|
||||||
|
sudo npm install -g pm2
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Configuration du projet et des variables d'environnement
|
||||||
|
|
||||||
|
1. Clonez ou transférez le dossier de l'application sur le serveur :
|
||||||
|
```bash
|
||||||
|
cd /var/www/
|
||||||
|
git clone <URL_DU_DEPOT> ferrovia-regional
|
||||||
|
cd ferrovia-regional
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Créez le fichier de variables d'environnement `.env.local` (ou `.env.production`) :
|
||||||
|
```bash
|
||||||
|
nano .env.local
|
||||||
|
```
|
||||||
|
*Renseignez vos identifiants Supabase :*
|
||||||
|
```env
|
||||||
|
NEXT_PUBLIC_SUPABASE_URL=https://votre-projet.supabase.co
|
||||||
|
NEXT_PUBLIC_SUPABASE_ANON_KEY=votre-cle-anon-supabase
|
||||||
|
PORT=3000
|
||||||
|
NODE_ENV=production
|
||||||
|
```
|
||||||
|
> ⚠️ **Important :** Les variables `NEXT_PUBLIC_*` sont intégrées par Next.js au moment de la commande `npm run build`. Assurez-vous que `.env.local` est bien présent **avant** d'exécuter le build.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Premier démarrage avec PM2
|
||||||
|
|
||||||
|
Exécutez les commandes suivantes :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Installation des dépendances
|
||||||
|
npm ci --prefer-offline || npm install
|
||||||
|
|
||||||
|
# 2. Compilation de production Next.js
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# 3. Démarrage de l'application via le fichier ecosystem
|
||||||
|
pm2 start ecosystem.config.cjs --env production
|
||||||
|
|
||||||
|
# 4. Sauvegarde de l'état PM2 et configuration du démarrage automatique au reboot
|
||||||
|
pm2 save
|
||||||
|
pm2 startup
|
||||||
|
```
|
||||||
|
*(Suivez l'instruction affichée par `pm2 startup` si une commande sudo vous est demandée).*
|
||||||
|
|
||||||
|
### Commandes utiles PM2 :
|
||||||
|
- Voir le statut : `pm2 status`
|
||||||
|
- Consulter les logs en temps réel : `pm2 logs ter-ferrovia`
|
||||||
|
- Redémarrer l'application sans coupure : `pm2 reload ter-ferrovia`
|
||||||
|
- Arrêter : `pm2 stop ter-ferrovia`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Configuration de Nginx (Reverse Proxy)
|
||||||
|
|
||||||
|
1. Copiez la configuration Nginx fournie :
|
||||||
|
```bash
|
||||||
|
sudo cp nginx/ter-ferrovia.mrpatator.fr.conf /etc/nginx/sites-available/ter-ferrovia.mrpatator.fr
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Activez le site :
|
||||||
|
```bash
|
||||||
|
sudo ln -s /etc/nginx/sites-available/ter-ferrovia.mrpatator.fr /etc/nginx/sites-enabled/
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Vérifiez la syntaxe Nginx et rechargez :
|
||||||
|
```bash
|
||||||
|
sudo nginx -t
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Activation du certificat HTTPS / SSL avec Certbot
|
||||||
|
|
||||||
|
Assurez-vous que l'enregistrement DNS **A** pour `ter-ferrovia.mrpatator.fr` pointe bien vers l'adresse IP de votre serveur, puis lancez :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo certbot --nginx -d ter-ferrovia.mrpatator.fr
|
||||||
|
```
|
||||||
|
|
||||||
|
Certbot configurera automatiquement le certificat SSL Let's Encrypt et activera le renouvellement automatique.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Mises à jour ultérieures (Déploiement Continu)
|
||||||
|
|
||||||
|
Pour appliquer de futures mises à jour sur le serveur :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Option 1 : Via le script automatisé
|
||||||
|
bash deploy.sh
|
||||||
|
|
||||||
|
# Option 2 : Manuellement
|
||||||
|
git pull
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
pm2 reload ecosystem.config.cjs --update-env
|
||||||
|
```
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# Script de déploiement automatisé pour TER Ferrovia Régional
|
||||||
|
# Domaine: ter-ferrovia.mrpatator.fr
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🚀 [1/5] Début du déploiement..."
|
||||||
|
|
||||||
|
# 1. Aller dans le dossier du projet
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
# 2. Récupérer les dernières modifications Git (si applicable)
|
||||||
|
if [ -d ".git" ]; then
|
||||||
|
echo "📥 [2/5] Récupération du code depuis Git..."
|
||||||
|
git pull origin main || git pull origin master || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. Installation des dépendances
|
||||||
|
echo "📦 [3/5] Installation des dépendances Node.js..."
|
||||||
|
npm ci --prefer-offline || npm install
|
||||||
|
|
||||||
|
# 4. Build de production Next.js
|
||||||
|
echo "🏗️ [4/5] Compilation de l'application Next.js (Production Build)..."
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# 5. Démarrage ou Rechargement avec PM2 sans coupure (zero downtime)
|
||||||
|
echo "⚡ [5/5] Rechargement du serveur PM2..."
|
||||||
|
if pm2 describe ter-ferrovia > /dev/null 2>&1; then
|
||||||
|
pm2 reload ecosystem.config.cjs --update-env
|
||||||
|
echo "✅ Application rechargée avec succès avec PM2 !"
|
||||||
|
else
|
||||||
|
pm2 start ecosystem.config.cjs --env production
|
||||||
|
pm2 save
|
||||||
|
echo "✅ Application démarrée avec succès avec PM2 !"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🎉 Déploiement terminé avec succès sur ter-ferrovia.mrpatator.fr !"
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
module.exports = {
|
||||||
|
apps: [
|
||||||
|
{
|
||||||
|
name: 'ter-ferrovia',
|
||||||
|
script: 'node_modules/next/dist/bin/next',
|
||||||
|
args: 'start -p 3000',
|
||||||
|
instances: 'max',
|
||||||
|
exec_mode: 'cluster',
|
||||||
|
autorestart: true,
|
||||||
|
watch: false,
|
||||||
|
max_memory_restart: '1G',
|
||||||
|
env: {
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
PORT: 3000,
|
||||||
|
},
|
||||||
|
env_production: {
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
PORT: 3000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
+1
-6
@@ -1,12 +1,7 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
/* config options here */
|
// Optionnel: configuration supplémentaire si nécessaire
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|
||||||
// next.config.js
|
|
||||||
module.exports = {
|
|
||||||
allowedDevOrigins: ['192.168.1.104'],
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
# ==============================================================================
|
||||||
|
# Configuration Nginx pour ter-ferrovia.mrpatator.fr
|
||||||
|
# Emplacement recommandé sur le serveur : /etc/nginx/sites-available/ter-ferrovia.mrpatator.fr
|
||||||
|
# Lien symbolique : sudo ln -s /etc/nginx/sites-available/ter-ferrovia.mrpatator.fr /etc/nginx/sites-enabled/
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
# Bloc HTTP : Redirection automatique vers HTTPS (une fois le certificat généré)
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
server_name ter-ferrovia.mrpatator.fr;
|
||||||
|
|
||||||
|
# Emplacement pour le challenge Let's Encrypt (Certbot)
|
||||||
|
location /.well-known/acme-challenge/ {
|
||||||
|
root /var/www/certbot;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Redirection vers HTTPS
|
||||||
|
location / {
|
||||||
|
return 301 https://$host$request_uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Bloc HTTPS : Reverse Proxy vers l'application Next.js (PM2 port 3000)
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
listen [::]:443 ssl http2;
|
||||||
|
server_name ter-ferrovia.mrpatator.fr;
|
||||||
|
|
||||||
|
# Certificats SSL (Générés par certbot --nginx -d ter-ferrovia.mrpatator.fr)
|
||||||
|
ssl_certificate /etc/letsencrypt/live/ter-ferrovia.mrpatator.fr/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/ter-ferrovia.mrpatator.fr/privkey.pem;
|
||||||
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
|
|
||||||
|
# Optimisation SSL
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
ssl_session_cache shared:SSL:10m;
|
||||||
|
ssl_session_timeout 1d;
|
||||||
|
|
||||||
|
# En-têtes de sécurité
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
add_header X-XSS-Protection "1; mode=block" always;
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||||
|
|
||||||
|
# Compression Gzip pour de meilleures performances
|
||||||
|
gzip on;
|
||||||
|
gzip_proxied any;
|
||||||
|
gzip_comp_level 6;
|
||||||
|
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
||||||
|
|
||||||
|
# Cache des fichiers statiques Next.js (_next/static)
|
||||||
|
location /_next/static/ {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
expires 365d;
|
||||||
|
access_log off;
|
||||||
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Reverse Proxy principal vers Next.js
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
# En-têtes pour WebSockets et Server-Sent Events
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
|
||||||
|
# En-têtes de transmission du client d'origine
|
||||||
|
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_set_header X-Forwarded-Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Port $server_port;
|
||||||
|
|
||||||
|
# Timeouts de proxy
|
||||||
|
proxy_connect_timeout 60s;
|
||||||
|
proxy_send_timeout 60s;
|
||||||
|
proxy_read_timeout 60s;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user