Files
LogWhispererAI/docs/reverse_proxy_setup.md
Luca Sacchi Ricciardi 26879acba4 feat: add production configuration with environment variables
- Add .env file for production deployment with reverse proxy
- Add docker-compose.prod.yml for production profile
- Add docker-compose.override.yml for local development
- Update docker-compose.yml with all configurable variables
- Update frontend to use VITE_* environment variables
- Update backend to support CORS_ORIGINS and WEBHOOK_BASE_URL
- Add vite.config.ts allowedHosts for reverse proxy
- Add documentation for docker-compose and reverse proxy setup

All URLs are now configurable via environment variables:
- VITE_API_URL: Backend API endpoint
- VITE_WEBHOOK_BASE_URL: Webhook base URL
- VITE_INSTALL_SCRIPT_URL: Install script URL
- VITE_APP_URL: Frontend URL
- CORS_ORIGINS: Allowed CORS origins
- WEBHOOK_BASE_URL: Backend webhook base URL
2026-04-03 18:49:53 +02:00

130 lines
3.9 KiB
Markdown

# Configurazione con Reverse Proxy
Questa guida spiega come configurare LogWhispererAI con un reverse proxy SSL.
## Scenario
Hai configurato:
- **Frontend**: `https://logwhispererai.lab.home.lucasacchi.net``http://192.168.254.79:5173`
- **Backend**: `https://srv-logwhispererai.lab.home.lucasacchi.net``http://192.168.254.79:3001`
## Configurazione
### 1. Crea il file di configurazione
Crea un file `.env` nella root del progetto:
```bash
cp .env.example .env
```
Modifica il file `.env` con i tuoi valori:
```env
# Frontend Configuration
VITE_API_URL=https://srv-logwhispererai.lab.home.lucasacchi.net
VITE_WEBHOOK_BASE_URL=https://logwhispererai.lab.home.lucasacchi.net/webhook
VITE_INSTALL_SCRIPT_URL=https://logwhispererai.lab.home.lucasacchi.net/install.sh
VITE_APP_NAME=LogWhispererAI
VITE_APP_URL=https://logwhispererai.lab.home.lucasacchi.net
# Backend Configuration
CORS_ORIGINS=https://logwhispererai.lab.home.lucasacchi.net
WEBHOOK_BASE_URL=https://logwhispererai.lab.home.lucasacchi.net/webhook
DELAY_MS=1500
NODE_ENV=production
```
### 2. Avvia i servizi
```bash
# Ferma eventuali container esistenti
docker compose down
# Avvia con le nuove variabili
docker compose up -d
```
### 3. Verifica la configurazione
Testa i vari endpoint:
```bash
# Health check backend
curl https://srv-logwhispererai.lab.home.lucasacchi.net/health
# Genera un webhook
curl -X POST https://srv-logwhispererai.lab.home.lucasacchi.net/api/webhook
# Analizza un log
curl -X POST https://srv-logwhispererai.lab.home.lucasacchi.net/api/analyze \
-H "Content-Type: application/json" \
-d '{"log": "FATAL: out of memory"}'
```
### 4. Verifica il frontend
Apri `https://logwhispererai.lab.home.lucasacchi.net` nel browser e verifica che:
1. La demo interattiva funzioni (chiama il backend corretto)
2. Lo step 2 dell'onboarding generi webhook con l'URL corretto
## Variabili d'Ambiente
### Frontend (VITE_*)
| Variabile | Descrizione | Esempio |
|-----------|-------------|---------|
| `VITE_API_URL` | URL del backend API | `https://srv-logwhispererai.lab.home.lucasacchi.net` |
| `VITE_WEBHOOK_BASE_URL` | Base URL per i webhook | `https://logwhispererai.lab.home.lucasacchi.net/webhook` |
| `VITE_INSTALL_SCRIPT_URL` | URL dello script di installazione | `https://logwhispererai.lab.home.lucasacchi.net/install.sh` |
| `VITE_APP_NAME` | Nome dell'applicazione | `LogWhispererAI` |
| `VITE_APP_URL` | URL pubblico dell'app | `https://logwhispererai.lab.home.lucasacchi.net` |
### Backend
| Variabile | Descrizione | Esempio |
|-----------|-------------|---------|
| `CORS_ORIGINS` | Origini CORS consentite (comma-separated) | `https://logwhispererai.lab.home.lucasacchi.net` |
| `WEBHOOK_BASE_URL` | Base URL per i webhook generati | `https://logwhispererai.lab.home.lucasacchi.net/webhook` |
| `DELAY_MS` | Delay simulato API (ms) | `1500` |
| `NODE_ENV` | Ambiente Node | `production` |
## File Configurati
- `frontend/.env` - Configurazione frontend per produzione
- `frontend/.env.development` - Configurazione per sviluppo locale
- `frontend/vite.config.ts` - Allow hosts per Vite
- `tools/fake-backend/server.js` - Supporto CORS dinamico e webhook URL configurabili
- `docker-compose.yml` - Passaggio variabili ai container
## Troubleshooting
### Errore "Blocked request" di Vite
Se vedi questo errore:
```
Blocked request. This host ("logwhispererai.lab.home.lucasacchi.net") is not allowed.
```
Aggiungi il dominio a `frontend/vite.config.ts`:
```typescript
server: {
allowedHosts: [
'logwhispererai.lab.home.lucasacchi.net',
],
}
```
### Errore CORS
Se il browser blocca le richieste API:
1. Verifica che `CORS_ORIGINS` includa il dominio del frontend
2. Ricostruisci il backend: `docker compose up fake-backend --build -d`
### Webhook URL errati
Se i webhook generati hanno URL sbagliati:
1. Verifica `WEBHOOK_BASE_URL` nel backend
2. Verifica `VITE_WEBHOOK_BASE_URL` nel frontend
3. Ricostruisci entrambi i servizi