Oddly enough this fixed it for me to, hopefully those searching for a** fix to nginx 502 bad gateway with NodeBB** come across this solution as it took me some time. I didn't think it would work because it was on the same server but it did.
proxy_pass http://mydomain.com:4567/;