# 502 Bad Gateway Fix - jadwaai.com

## Date
2026-03-17

## Issue
nginx returning `502 Bad Gateway` for jadwaai.com

## Root Cause
nginx configuration was proxying to `http://127.0.0.1:4006` but the Flask app was running on port `5006`

## Error Log
```
connect() failed (111: Connection refused) while connecting to upstream, client: ..., server: jadwaai.com.happy-times.me, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:4006/", host: "jadwaai.com"
```

## App Details
- **App**: Flask/Python (managed by PM2)
- **PM2 config**: `/home/ashraffarid2010/jadwaai.com/ecosystem.config.json`
- **PM2 name**: `jadwaai`
- **Actual port**: `5006`
- **Nginx config file**: `/etc/nginx/conf.d/users/ashraffarid2010.conf`

## Fix Applied
```bash
# Remove immutable flag, update port, restore flag
sudo chattr -i /etc/nginx/conf.d/users/ashraffarid2010.conf
sudo sed -i 's|proxy_pass http://127.0.0.1:4006|proxy_pass http://127.0.0.1:5006|g' /etc/nginx/conf.d/users/ashraffarid2010.conf
sudo chattr +i /etc/nginx/conf.d/users/ashraffarid2010.conf

# Reload nginx
systemctl reload nginx
```

## Verification
```bash
curl -I http://jadwaai.com
# Returns: HTTP/1.1 200 OK
```

## Notes for Future
- Check actual app port with: `ss -tlnp | grep <port>`
- Check PM2 status with: `pm2 status`
- Check PM2 logs with: `pm2 logs jadwaai --lines 30`
- Nginx config has immutable flag (`chattr +i`), requires removing before edits
