I was also getting 502 Bad Gateway. The problem was that I was missing loading the http-bind module in ejabberd: {modules, [ ... {mod_http_bind, []}, Posted at Nginx Forum: http://forum.nginx.org/read.php?2,657,162067#msg-162067