I'm just going to leave this here @Magiichan : https://www.scalescale.com/tips/nginx/502-bad-gateway-using-nginx/ http://jvdc.me/fix-502-bad-gateway-error-on-nginx-server-after-upgrading-php/
did you check the first link? I don't know what you are doing on the back end so I tried to provide you with multiple solutions