aaP_fallingrais Hmmm, did you well restart the web server service (nginx or apache?) after the modification in conf? Did you test the validity of the overall config (e.g. "nginx -t") with success?
About the 502 Bad Gateway, it says that the proxy received an invalid response from the upstream server... It could be because there's no valid certificate at a point, because the target server doesn't listen to the port 443 on the right IP, because there's too many redirections (e.g. sometimes when the proxy sends the wrong scheme in headers* and final server is trying to force SSL while it's already there)... Well, first, maybe you should look at both server logs.
*proxy_set_header X-Forwarded-Proto http;