Nextcloud and Argo Tunnel Bad Gateway

Maybe it would work by defining https://localhost:443?

May I ask your own self-signed certificate or Cloudflare Origin CA Certificate?
Furthermore, before moving to Cloudflare, was your Website working over HTTPS connection? If so, did you had an valid SSL certificate installed at your origin host / server which covers both your naked (root) domain any any other needed sub-domain like www, mail, etc.?

May I ask what SSL option have you got selected under the SSL/TLS tab at Cloudflare dashboard for your domain ( Flexible, Full, Full Strict … )?

Haven’t tried Nextcloud via Cloudflare Tunnel yet and by that I cannot write some more helpful information.

Is your origin host working over the desired 443 port for HTTPS?

May I ask is the 502 error comming from origin host / server or Cloudflare 502 error page?

Do you mean like from HTTP to HTTPS or non-www to www (or vice versa maybe?)?