Getting Bad gateway Error code 502

This means your cloudflared is able to establish a secure connection between your origin and Cloudflare, but doesn’t mean that cloudflared is able to communicate with the service that you’ve configured.

Anyway, the best way to investigate is to check the cloudflared logs. If you installed cloudflared via dashboard, then by default logging is not enabled hence you need to manually modify the service parameters so that it can perform logging related to any errors.

However, based on my experience, if the website suddenly returns Error 502 when access from external but accessible from the internal, it might be due to expired SSL certificate in the web server (particularly, your Nginx proxy manager). If you wish to verify the issue quickly, you can enable No TLS Verify option in the tunnel public hostnames configuration (particularly, TLS)