#!/bin/bash
# Troubleshooting script voor test.baro-edegem.com
# Run dit als er problemen zijn

echo "=========================================="
echo "DIAGNOSTICS: test.baro-edegem.com"
echo "=========================================="
echo ""

echo "1. DNS Check:"
echo "-------------"
dig +short test.baro-edegem.com
echo ""

echo "2. Nginx Status:"
echo "----------------"
sudo systemctl status nginx --no-pager -l
echo ""

echo "3. Nginx Config Test:"
echo "---------------------"
sudo nginx -t
echo ""

echo "4. Directory Check:"
echo "-------------------"
ls -la /var/www/testbaro/
echo ""

echo "5. Recent Access Logs (laatste 10):"
echo "------------------------------------"
sudo tail -n 10 /var/log/nginx/test.baro-edegem.com.access.log 2>/dev/null || echo "Log file not found"
echo ""

echo "6. Recent Error Logs (laatste 10):"
echo "-----------------------------------"
sudo tail -n 10 /var/log/nginx/test.baro-edegem.com.error.log 2>/dev/null || echo "Log file not found"
echo ""

echo "7. Nginx Config Dump:"
echo "---------------------"
if [ -f "/etc/nginx/sites-available/test.baro-edegem.com" ]; then
    sudo cat /etc/nginx/sites-available/test.baro-edegem.com
elif [ -f "/etc/nginx/conf.d/test.baro-edegem.com.conf" ]; then
    sudo cat /etc/nginx/conf.d/test.baro-edegem.com.conf
else
    echo "Config file not found!"
fi
echo ""

echo "8. Port Check (80 en 443):"
echo "--------------------------"
sudo netstat -tlnp | grep -E ':80|:443' || sudo ss -tlnp | grep -E ':80|:443'
echo ""

echo "9. Curl Test (HTTP):"
echo "--------------------"
curl -v http://test.baro-edegem.com 2>&1 | head -20
echo ""

echo "10. Curl Test (HTTPS - als geconfigureerd):"
echo "--------------------------------------------"
curl -vk https://test.baro-edegem.com 2>&1 | head -20
echo ""

echo "=========================================="
echo "DIAGNOSTICS COMPLEET"
echo "=========================================="
