Oh yuck!
Any 502 error can be troubling, because it is an HTTP Status Code, whose text is displayed differently based on the server hosting the page you are trying to access and the web browser you are accessing it from (probably a couple other factors as well).
Most often this is some type of server error, but it can also be a localized issue, in how the web browser you are using, manages its browser cache.
The best way to start troubleshooting this issue further, is to look through your server logs. If the error is occurring at a specific time of day, it may be due to some script (or API) that runs on your website or on the server itself. If the error occurs when accessing a specific page, you can drill down into that page.
One thing is for sure, there is always a reason, it just isn’t always easy to find. If it seems like the error is occurring randomly, try researching things like the MySQL Server logs, server disk space/usage and your own personal computer (web browser cache management).
Specifically, I’d be interested in the output of the:
SHOW BINARY LOGS
…MySQL/MariaDB command, and the:
df -h
…linux command.
These may have absolutely nothing to do with the situation and there may be loads of people who don’t think the information would be relevant. However, I suspect MySQL issues could cause 502 errors just as easily as other sources, especially if database binlog files are eating up your disk space, leaving little/no room for things like caching.