502 Bad Gateway occurs if your Mac (or any number of other steps along the way) receives a nonsensical answer from the website it's trying to access. Like asking "what day is it" and getting "strawberry" for an answer.
Here are a few troubleshooting steps that may help:
If you can't open a website in Safari on Mac - Apple Support
Needless to say, if you are using, or have used at any time in the past, any non-Apple "anti-virus", "cleaning", or "Internet security" products including "banking security", anything at all in that broad category of utterly useless garbage, don't. A lot of things won't work if you do.