I think almost all of the threads here about 502 errors are when Discourse has been upgraded and it hasn’t come back to life. The upgrade failed, or the admin didn’t wait long enough for the service to come up.
Are you saying that you have a working Discourse, take no admin action, but it starts returning 502 spontaneously?
And when it does that, does it always return 502 until restarted or is it intermittently working again?