# BTCPay Server 502 Bad Gateway - Emergency Fix

## Quick SSH Access
```bash
# From Windows/WSL:
ssh -p 2255 root@thebankofdebbie.giize.com
# Password: Th3fa1r13sd1d1t.
```

## Immediate Fix Commands (Run as root)

### Option 1: Quick Restart (Try First)
```bash
cd /opt/btcpayserver-docker
./btcpay-restart.sh
```

### Option 2: Check and Fix Specific Issues
```bash
# Check what's running
docker ps -a

# Restart stopped containers
docker start generated_btcpayserver_1
docker start generated_nginx_1
docker start generated_postgres_1

# Check logs for errors
docker logs generated_btcpayserver_1 --tail 50
docker logs generated_nginx_1 --tail 30
```

### Option 3: Full Docker Restart
```bash
# Restart Docker daemon
systemctl restart docker

# Wait 30 seconds
sleep 30

# Restart BTCPay
cd /opt/btcpayserver-docker
./btcpay-restart.sh
```

### Option 4: Rebuild Configuration
```bash
# Reload environment
source /opt/.env

# Regenerate and restart
cd /opt/btcpayserver-docker
./btcpay-setup.sh -i
```

## Common Causes & Solutions

### 1. Disk Space Full
```bash
# Check space
df -h /

# Clean Docker
docker system prune -a --volumes
# WARNING: This removes unused data!
```

### 2. Memory Issues
```bash
# Check memory
free -h

# Restart to free memory
systemctl restart docker
```

### 3. Database Corruption
```bash
# Check PostgreSQL
docker logs generated_postgres_1 --tail 100 | grep ERROR

# If corrupted, may need to restore from backup
```

### 4. Certificate Issues
```bash
# Check certificate
docker logs generated_letsencrypt-nginx-proxy-companion_1 --tail 50

# Force renewal if needed
docker exec generated_letsencrypt-nginx-proxy-companion_1 /app/force_renew
```

## Monitor After Fix
```bash
# Watch container status
watch docker ps

# Check if site is up
curl -I https://thebankofdebbie.giize.com

# Monitor logs
docker logs -f generated_btcpayserver_1
```

## If Nothing Works

1. **Check Hostinger Panel**: Ensure VPS is running and not suspended
2. **Check DNS**: Verify domain still points to correct IP
3. **Restore from Backup**: Use the backup we just created

## Prevention
- Set up monitoring: `uptimerobot.com` for free monitoring
- Regular backups: Run backup script weekly
- Check disk space: Add cron job to alert on low space

## Contact Support
- BTCPay Discord: https://chat.btcpayserver.org/
- Hostinger Support: If VPS issue