502 Bad Gateway in conjunction with Nginx Reverse Proxy

Check out Setting up secure HTTP (HTTPS) with AMP
Your nginx config seems to be wrong as the destination is wrong.