Diagnóstico y fix SQL Server: SERVERNAME, TDS_Version, Puerto explicitos
This commit is contained in:
164
deploy/DEPLOYMENT_GUIDE_UBUNTU.md
Normal file
164
deploy/DEPLOYMENT_GUIDE_UBUNTU.md
Normal file
@@ -0,0 +1,164 @@
|
||||
# Guía de Despliegue en Ubuntu Server (Dashboard Leads)
|
||||
|
||||
Esta guía explica el proceso paso a paso para desplegar la aplicación **Dashboard Leads** (Frontend React + Vite y Backend FastAPI) en un servidor **Ubuntu Server 20.04 / 22.04 / 24.04 LTS**.
|
||||
|
||||
---
|
||||
|
||||
## 1. Requisitos Previos en el Servidor Ubuntu
|
||||
|
||||
Conéctate por SSH a tu servidor e instala los paquetes necesarios:
|
||||
|
||||
```bash
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
sudo apt install -y python3 python3-pip python3-venv nodejs npm nginx certbot python3-certbot-nginx git
|
||||
```
|
||||
|
||||
*(Opcional: Si requieres conectar a SQL Server mediante pyodbc en Ubuntu, instala msodbcsql18 y unixodbc-dev).*
|
||||
|
||||
---
|
||||
|
||||
## 2. Estructura de Directorios en el Servidor
|
||||
|
||||
Crea el directorio del proyecto y otorga permisos al usuario actual (ejemplo: `ubuntu`):
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /var/www/dashboard-leads
|
||||
sudo chown -R $USER:$USER /var/www/dashboard-leads
|
||||
```
|
||||
|
||||
Sube los archivos del proyecto a `/var/www/dashboard-leads/` (o clónalos mediante git).
|
||||
|
||||
---
|
||||
|
||||
## 3. Configuración del Backend (FastAPI)
|
||||
|
||||
1. Ve a la carpeta `backend`:
|
||||
```bash
|
||||
cd /var/www/dashboard-leads/backend
|
||||
```
|
||||
|
||||
2. Crea el entorno virtual e instala dependencias:
|
||||
```bash
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Configura las variables de entorno `.env`:
|
||||
- Copia la plantilla `.env.example`:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
- Edita las credenciales reales de forma segura:
|
||||
```bash
|
||||
nano .env
|
||||
```
|
||||
- Verifica que la variable `CORS_ORIGINS` contenga tus dominios:
|
||||
```env
|
||||
CORS_ORIGINS=https://dashboard-leads.escueladerefrigeracion.lat,http://dashboard-leads.escueladerefrigeracion.lat,http://api-leads.escueladerefrigeracion.lat
|
||||
```
|
||||
|
||||
4. Prueba la ejecución manual del backend:
|
||||
```bash
|
||||
uvicorn main:app --host 127.0.0.1 --port 8001
|
||||
```
|
||||
*(Presiona `Ctrl + C` para detener después de verificar).*
|
||||
|
||||
---
|
||||
|
||||
## 4. Configuración del Servicio Systemd para Backend
|
||||
|
||||
1. Copia el archivo de servicio `dashboard-leads-backend.service`:
|
||||
```bash
|
||||
sudo cp /var/www/dashboard-leads/deploy/dashboard-leads-backend.service /etc/systemd/system/
|
||||
```
|
||||
|
||||
2. Recarga systemd, inicia y habilita el servicio:
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl start dashboard-leads-backend
|
||||
sudo systemctl enable dashboard-leads-backend
|
||||
```
|
||||
|
||||
3. Revisa el estado del servicio:
|
||||
```bash
|
||||
sudo systemctl status dashboard-leads-backend
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Configuración y Compilación del Frontend (React + Vite)
|
||||
|
||||
1. Ve a la carpeta `frontend`:
|
||||
```bash
|
||||
cd /var/www/dashboard-leads/frontend
|
||||
```
|
||||
|
||||
2. Configura la variable de entorno en `.env`:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
nano .env
|
||||
```
|
||||
Asegúrate de que contenga la URL del backend:
|
||||
```env
|
||||
VITE_API_BASE_URL=https://api-leads.escueladerefrigeracion.lat
|
||||
```
|
||||
*(Recomendado usar HTTPS para evitar advertencias de Mixed Content en el navegador).*
|
||||
|
||||
3. Instala dependencias y genera la build de producción:
|
||||
```bash
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
Esto generará los archivos finales en `/var/www/dashboard-leads/frontend/dist`.
|
||||
|
||||
---
|
||||
|
||||
## 6. Configuración de Nginx
|
||||
|
||||
1. Copia el archivo de configuración de Nginx:
|
||||
```bash
|
||||
sudo cp /var/www/dashboard-leads/deploy/nginx-leads.conf /etc/nginx/sites-available/leads.conf
|
||||
```
|
||||
|
||||
2. Crea el enlace simbólico para activarlo:
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/leads.conf /etc/nginx/sites-enabled/
|
||||
```
|
||||
|
||||
3. Prueba la sintaxis de Nginx y recárgalo:
|
||||
```bash
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. Configuración de Certificados SSL (HTTPS Gratis con Certbot)
|
||||
|
||||
Para habilitar SSL en ambos dominios y proteger las transmisiones:
|
||||
|
||||
```bash
|
||||
sudo certbot --nginx -d dashboard-leads.escueladerefrigeracion.lat -d api-leads.escueladerefrigeracion.lat
|
||||
```
|
||||
|
||||
Certbot actualizará automáticamente la configuración de Nginx para redirigir todo el tráfico a HTTPS de forma segura.
|
||||
|
||||
---
|
||||
|
||||
## 8. Mantenimiento y Comandos Útiles
|
||||
|
||||
- **Ver logs del Backend**:
|
||||
```bash
|
||||
journalctl -u dashboard-leads-backend -f
|
||||
```
|
||||
- **Reiniciar el Backend**:
|
||||
```bash
|
||||
sudo systemctl restart dashboard-leads-backend
|
||||
```
|
||||
- **Actualizar cambios en Frontend**:
|
||||
```bash
|
||||
cd /var/www/dashboard-leads/frontend
|
||||
npm run build
|
||||
```
|
||||
14
deploy/dashboard-leads-backend.service
Normal file
14
deploy/dashboard-leads-backend.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Dashboard Leads Backend Service (FastAPI)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=ubuntu
|
||||
WorkingDirectory=/var/www/dashboard-leads/backend
|
||||
ExecStart=/var/www/dashboard-leads/backend/venv/bin/uvicorn main:app --host 127.0.0.1 --port 8001 --workers 2
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
EnvironmentFile=/var/www/dashboard-leads/backend/.env
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
46
deploy/nginx-leads.conf
Normal file
46
deploy/nginx-leads.conf
Normal file
@@ -0,0 +1,46 @@
|
||||
# Configuración de Nginx para Dashboard Leads (Ubuntu Server)
|
||||
|
||||
# 1. FRONTEND: https://dashboard-leads.escueladerefrigeracion.lat
|
||||
server {
|
||||
listen 80;
|
||||
server_name dashboard-leads.escueladerefrigeracion.lat;
|
||||
|
||||
# Ruta a la carpeta dist del frontend construida con 'npm run build'
|
||||
root /var/www/dashboard-leads/frontend/dist;
|
||||
index index.html;
|
||||
|
||||
# Compresión Gzip
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Caché de archivos estáticos
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, no-transform";
|
||||
}
|
||||
}
|
||||
|
||||
# 2. BACKEND: http://api-leads.escueladerefrigeracion.lat
|
||||
server {
|
||||
listen 80;
|
||||
server_name api-leads.escueladerefrigeracion.lat;
|
||||
|
||||
client_max_body_size 50M;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:8001;
|
||||
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;
|
||||
|
||||
# Timeouts para cargas largas si aplica
|
||||
proxy_connect_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
proxy_read_timeout 300s;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user