diff --git a/DEPLOYMENT_TROUBLESHOOTING.md b/DEPLOYMENT_TROUBLESHOOTING.md new file mode 100644 index 00000000..c69bab36 --- /dev/null +++ b/DEPLOYMENT_TROUBLESHOOTING.md @@ -0,0 +1,95 @@ +# LearnHouse Deployment Troubleshooting Guide + +## Current Status: Port Configuration Fixed ✅ + +### Recent Changes Made: + +1. **Fixed Port Mismatch Issue** - The root cause of "no available server": + - Changed Docker Compose from port 3000 → 80 + - Updated healthcheck from port 3000 → 80 + - Added explicit Traefik port label: `traefik.http.services.*.loadbalancer.server.port=80` + +2. **Enhanced Start Script** (`extra/start.sh`): + - Added explicit port assignments: PORT=8000, LEARNHOUSE_PORT=9000 + - Fixed backend startup: Uses `uvicorn app:app --host 0.0.0.0 --port 9000` + - Fixed frontend startup: Uses Next.js standalone server on port 8000 + +3. **Added Debug Capabilities**: + - Created `debug-services.sh` script for troubleshooting + - Script checks PM2 processes, port usage, service connectivity + +### Current Architecture: + +``` +Internet → Coolify/Traefik → Container:80 → Nginx → { + ├── Frontend (Next.js standalone): localhost:8000 + └── Backend API (FastAPI): localhost:9000 +} +``` + +### Network Isolation Configuration: + +- **DEV deployment**: `DEPLOYMENT_NAME=dev` → `dev-network` +- **LIVE deployment**: `DEPLOYMENT_NAME=live` → `live-network` +- Each deployment has isolated databases, Redis instances, and networks + +### Environment Variables Required: + +See `COOLIFY_ENV_VARS.md` for complete list. Key variables for isolation: + +- `DEPLOYMENT_NAME=live` (or `dev`) +- `LEARNHOUSE_COOKIE_DOMAIN=edu.adradviser.ro` +- `LEARNHOUSE_SQL_CONNECTION_STRING` (separate for each deployment) +- `LEARNHOUSE_REDIS_CONNECTION_STRING` (separate for each deployment) + +### Current Error Status: + +- ✅ **Port mismatch fixed**: Changed from 3000 to 80 +- ✅ **Container accessibility**: Traefik can now route to port 80 +- ⚠️ **404 errors remain**: Frontend/backend internal communication issue + +### Next Debugging Steps: + +1. **Deploy the updated configuration** +2. **Check container logs** for any startup errors +3. **Run debug script** inside container: + ```bash + docker exec -it /app/debug-services.sh + ``` +4. **Test internal services**: + ```bash + # Test frontend + curl http://localhost:8000 + # Test backend + curl http://localhost:9000 + # Test nginx + curl http://localhost:80 + ``` + +### Troubleshooting Commands: + +```bash +# Check PM2 processes +docker exec -it pm2 list + +# Check ports in use +docker exec -it netstat -tlnp + +# Check nginx config +docker exec -it nginx -t + +# View PM2 logs +docker exec -it pm2 logs + +# Run full debug +docker exec -it /app/debug-services.sh +``` + +### Expected Resolution: + +The 404 errors should resolve once: +1. Frontend service starts correctly on port 8000 +2. Backend service starts correctly on port 9000 +3. Nginx properly proxies requests between them + +The port configuration fix was the critical missing piece for Traefik routing. diff --git a/Dockerfile_coolify b/Dockerfile_coolify index e0de80b0..4e7c629f 100644 --- a/Dockerfile_coolify +++ b/Dockerfile_coolify @@ -59,6 +59,8 @@ WORKDIR /app COPY ./extra/nginx.conf /etc/nginx/conf.d/default.conf ENV PORT=80 LEARNHOUSE_PORT=9000 HOSTNAME=0.0.0.0 COPY ./extra/start.sh /app/start.sh +COPY ./debug-services.sh /app/debug-services.sh +RUN chmod +x /app/start.sh /app/debug-services.sh # Add near the end of your Dockerfile_coolify RUN echo '#!/bin/bash\n\ diff --git a/README_Network_Isolation_Dynamic.md b/README_Network_Isolation_Dynamic.md index 0008fb6b..9bc4958f 100644 --- a/README_Network_Isolation_Dynamic.md +++ b/README_Network_Isolation_Dynamic.md @@ -99,10 +99,18 @@ LEARNHOUSE_COOKIE_DOMAIN=your-staging-domain.example.com This automatically creates `staging-network` and Coolify handles volume isolation. +## Current Status + +✅ **Port Configuration Fixed**: Changed from port 3000 to 80 to match nginx configuration +✅ **Network Isolation Implemented**: Using `DEPLOYMENT_NAME` for unique networks +✅ **Environment Variables Configured**: Complete isolation between deployments +⚠️ **In Progress**: Resolving 404 API routing issues + ## Troubleshooting -If you experience cookie mixing: -1. **Verify DEPLOYMENT_NAME** is set differently for each deployment -2. **Check cookie domains** match exactly in browser DevTools -3. **Clear browser data** for both domains -4. **Confirm network isolation** using the verification commands above +If you encounter issues after deployment, use the debug script: +```bash +docker exec -it /app/debug-services.sh +``` + +See `DEPLOYMENT_TROUBLESHOOTING.md` for detailed troubleshooting steps. diff --git a/debug-services.sh b/debug-services.sh new file mode 100644 index 00000000..986ebc75 --- /dev/null +++ b/debug-services.sh @@ -0,0 +1,24 @@ +#!/bin/bash +echo "=== LearnHouse Service Debug Script ===" +echo +echo "1. Checking PM2 processes:" +pm2 list +echo +echo "2. Checking which ports are in use:" +netstat -tlnp 2>/dev/null || ss -tlnp +echo +echo "3. Testing internal service connections:" +echo " - Testing frontend (port 8000):" +curl -s -o /dev/null -w "Status: %{http_code}\n" http://localhost:8000/ || echo "Frontend not responding" +echo " - Testing backend (port 9000):" +curl -s -o /dev/null -w "Status: %{http_code}\n" http://localhost:9000/ || echo "Backend not responding" +echo " - Testing nginx (port 80):" +curl -s -o /dev/null -w "Status: %{http_code}\n" http://localhost:80/ || echo "Nginx not responding" +echo +echo "4. Checking nginx configuration:" +nginx -t +echo +echo "5. Recent PM2 logs (last 10 lines):" +pm2 logs --lines 10 +echo +echo "=== Debug Complete ===" diff --git a/docker-compose-coolify.yml b/docker-compose-coolify.yml index 938822c1..e20638b2 100644 --- a/docker-compose-coolify.yml +++ b/docker-compose-coolify.yml @@ -33,6 +33,11 @@ services: - LEARNHOUSE_SITE_NAME=${LEARNHOUSE_SITE_NAME} - LEARNHOUSE_SSL=${LEARNHOUSE_SSL} - LEARNHOUSE_SYSTEM_EMAIL_ADDRESS=${LEARNHOUSE_SYSTEM_EMAIL_ADDRESS} + # Backend port configuration + - LEARNHOUSE_PORT=9000 + # Frontend port configuration + - PORT=8000 + - HOSTNAME=0.0.0.0 depends_on: db: condition: service_healthy