Skip to content

Instantly share code, notes, and snippets.

@tnm
Created November 12, 2025 23:37
Show Gist options
  • Select an option

  • Save tnm/854fa478d215c3b89b3274eb76427df0 to your computer and use it in GitHub Desktop.

Select an option

Save tnm/854fa478d215c3b89b3274eb76427df0 to your computer and use it in GitHub Desktop.
Debug commands for Cased CD Enterprise 502 Bad Gateway error

Debug Commands for Cased CD Enterprise 502 Error

Run these commands inside the pod to diagnose the 502 Bad Gateway issue.

Priority 1: Check Backend Status

# 1. Check if the backend process is running
ps aux | grep cased-backend

Expected output: Should show /app/cased-backend process running

# 2. Test backend directly (should return "OK")
curl -v http://127.0.0.1:8081/health

Expected output: OK

# 3. Check what port the backend is listening on
netstat -tlnp | grep 8081

Expected output: Should show 0.0.0.0:8081 or 127.0.0.1:8081

Priority 2: Check Nginx Configuration

# 4. Check nginx error logs for more details
tail -50 /var/log/nginx/error.log

Look for errors related to:

  • DNS resolution failures
  • Connection refused
  • Upstream timeout
# 5. Check what's the proxy_target in nginx config
cat /tmp/nginx.conf | grep -A2 "set \$proxy_target"

Expected output: set $proxy_target "http://localhost:8081";

# 6. Check DNS resolver in nginx config
cat /tmp/nginx.conf | grep resolver

Expected output: resolver <IP> valid=10s ipv6=off;

Priority 3: Test DNS and Network

# 7. Test if nginx can resolve localhost via DNS
nslookup localhost

Important: This will likely fail! Nginx resolver only queries DNS, not /etc/hosts

# 8. Check if backend is accessible on localhost
curl -v http://localhost:8081/health

Expected output: OK

# 9. Check environment variables
env | grep -E '(BACKEND_PORT|PROXY_TARGET|DNS_RESOLVER)'

Expected output:

BACKEND_PORT=8081
PROXY_TARGET=http://localhost:8081
DNS_RESOLVER=<IP>

Priority 4: Check Logs

# 10. Check recent nginx access logs for API requests
tail -100 /var/log/nginx/access.log | grep "api/v1/settings"

Look for 502 errors

Quick Test: Direct Backend Access

# Try accessing backend API endpoint directly
curl http://127.0.0.1:8081/api/v1/settings/audit

If this works but nginx proxy doesn't, it's definitely a proxy configuration issue.

What to Look For

If backend is NOT running:

  • Check pod logs: kubectl logs <pod-name> -n argocd
  • Look for backend startup errors
  • Check if backend binary exists: ls -la /app/cased-backend

If backend IS running but not accessible:

  • Check if listening on correct interface (should be 0.0.0.0:8081)
  • Check firewall rules (unlikely in container)

If nginx can't reach backend:

  • Check nginx error logs for "upstream" errors
  • Check if localhost resolves (it probably won't via DNS)
  • Try using 127.0.0.1 instead in nginx config

Expected Root Cause

Based on the symptoms, the most likely issue is:

Nginx resolver can't find localhost because:

  1. Nginx's resolver directive only queries DNS servers
  2. DNS servers don't have a record for "localhost"
  3. Even though /etc/hosts has 127.0.0.1 localhost, nginx's resolver ignores it

Solution: Use 127.0.0.1 directly instead of localhost in the nginx proxy configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment