- Kestrel ora ascolta su 0.0.0.0:8080 per compatibilità Docker - HTTPS redirect attivo solo in sviluppo, disabilitato in prod - Aggiunta sezione "Kestrel" in appsettings.json e nuovo appsettings.Production.json con limiti di sicurezza - Healthcheck Docker ora usa wget su /health (porta 8080) - Aggiunta documentazione dettagliata in BROWSER_ACCESS_CONFIG.md - Migliorata accessibilità browser, supporto reverse proxy e SignalR
6.8 KiB
? CONFIGURAZIONE UI BROWSER - TradingBot Blazor Server
?? Modifiche Applicate per Accessibilità Browser
? 1. Program.cs - Configurazione Kestrel
Configurato Kestrel per ascoltare su tutte le interfacce in Docker:
builder.WebHost.ConfigureKestrel(serverOptions =>
{
// Listen su porta 8080 per Docker
serverOptions.ListenAnyIP(8080);
});
HTTPS Redirect disabilitato in Production:
// Solo in Development
if (app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}
Perché: In Docker, HTTPS è gestito da reverse proxy (se usato). Il redirect HTTPS causa problemi di accesso.
? 2. appsettings.json - Kestrel Endpoints
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:8080"
}
}
}
}
0.0.0.0: Listen su tutte le interfacce (necessario per Docker)
:8080: Porta standard per l'applicazione
? 3. appsettings.Production.json - Config Docker
Creato file specifico per ambiente Production (Docker):
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:8080"
}
},
"Limits": {
"MaxRequestBodySize": 10485760
}
}
}
MaxRequestBodySize: 10MB limit per sicurezza
? 4. docker-compose.yml - Health Check
Aggiornato health check per usare wget:
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/health"]
Prima: Usava curl (non disponibile)
Dopo: Usa wget (installato nel Dockerfile)
?? Come Accedere all'UI
Sviluppo Locale (senza Docker)
dotnet run
URL:
https://localhost:5001 # HTTPS
http://localhost:5000 # HTTP (redirect a HTTPS)
Docker Locale
docker-compose up -d
URL:
http://localhost:8080
Unraid/Produzione
Dopo deploy su Unraid:
URL:
http://[UNRAID-IP]:8080
Esempio:
http://192.168.30.23:8080
?? Verifica Accesso
Test Health Endpoint
Locale:
curl http://localhost:8080/health
# Output: Healthy
Docker:
docker exec tradingbot wget --no-verbose --tries=1 --spider http://localhost:8080/health
# Output: 200 OK
Test UI Completo
- Apri browser
- Vai su:
http://localhost:8080(o IP Unraid) - Dovresti vedere: Dashboard TradingBot
Elementi visibili:
- ? Sidebar con logo e menu
- ? Dashboard con grafici
- ? Navigazione funzionante
- ? SignalR connesso (real-time updates)
?? Troubleshooting Accesso
Problema 1: "This site can't be reached"
Causa: Container non in ascolto su interfaccia corretta
Verifica:
docker exec tradingbot netstat -tuln | grep 8080
Dovrebbe mostrare:
tcp6 0 0 :::8080 :::* LISTEN
Fix: Già applicato in appsettings.json con 0.0.0.0:8080
Problema 2: ERR_SSL_PROTOCOL_ERROR
Causa: Tentativo HTTPS su porta HTTP
Soluzione: Usa http:// NON https://
? http://192.168.30.23:8080
? https://192.168.30.23:8080
Fix: Già applicato disabilitando HTTPS redirect in production
Problema 3: 502 Bad Gateway (con reverse proxy)
Causa: Reverse proxy non riesce a connettersi
Nginx config:
location / {
proxy_pass http://tradingbot:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
Problema 4: Blazor SignalR Disconnection
Sintomo: UI non si aggiorna in tempo reale
Verifica in console browser (F12):
SignalR connection failed
Fix: Assicurati che WebSocket siano abilitati:
// Program.cs - già presente
.AddInteractiveServerComponents();
?? Port Mapping
Architettura
Browser ? Port 8080 ? Docker Container ? Kestrel:8080 ? Blazor App
Docker Port Mapping
# docker-compose.yml
ports:
- "8080:8080"
# ? ?
# | ?? Container internal port (Kestrel)
# ???????? Host external port (accesso da browser)
Host Port: Porta su cui accedi da browser
Container Port: Porta su cui Kestrel ascolta dentro il container
?? Security Considerations
Production Deployment
Se esponi pubblicamente, considera:
1. HTTPS con Reverse Proxy
Usa Nginx Proxy Manager o Traefik:
Browser (HTTPS) ? Nginx:443 ? TradingBot:8080 (HTTP interno)
2. Autenticazione
Aggiungi autenticazione ASP.NET Core:
builder.Services.AddAuthentication(...)
.AddCookie(...);
3. IP Whitelist
Limita accesso a IP fidati:
# docker-compose.yml
ports:
- "127.0.0.1:8080:8080" # Solo localhost
? Checklist Configurazione
Pre-Deploy
- Kestrel configurato per
0.0.0.0:8080 - HTTPS redirect disabilitato in Production
- Health endpoint
/healthattivo - Port 8080 esposta in Docker
Docker
ASPNETCORE_URLS=http://+:8080in env- Port mapping
8080:8080in compose - Health check con
wgetfunzionante - Volume per dati persistenti
Blazor
- Interactive Server Components abilitati
- SignalR configurato automaticamente
- Antiforgery abilitato
- Static files serviti
Testing
- Build successful (
dotnet build) - Docker build successful (
docker-compose build) - Container running (
docker ps) - Health check passing (status: healthy)
- UI accessibile via browser
- SignalR funzionante (real-time updates)
?? Quick Test dopo Deploy
Step 1: Deploy
git add .
git commit -m "fix: Configure Kestrel for Docker browser access"
git push origin main
Step 2: Portainer Deploy
Segui la guida: PORTAINER_DEPLOYMENT_GUIDE.md
Step 3: Test Access
Terminal:
# Health check
curl http://192.168.30.23:8080/health
# Output atteso: Healthy
Browser:
http://192.168.30.23:8080
Dovresti vedere:
???????????????????????????????????
? ?? TradingBot ?
? ? ATTIVO ?
???????????????????????????????????
? ?? Dashboard ?
? Portfolio: $15,000 ?
? Grafici real-time ?
???????????????????????????????????
?? File Modificati
- ?
Program.cs- Kestrel config, HTTPS redirect - ?
appsettings.json- Kestrel endpoints - ?
appsettings.Production.json- Production config (nuovo) - ?
docker-compose.yml- Health check wget
?? Risultato
? Applicazione Blazor completamente accessibile via browser
? Configurazione ottimizzata per Docker
? Health check funzionante
? SignalR real-time updates operativi
? Pronta per deploy su Unraid
Status: ? Configurato e Testato
Build: ? Successful
Browser Ready: ? Yes
Docker Ready: ? Yes