You could check the error log to see why nginx is throwing a 502 error by adding
error_log logs/error.log to nginx.conf.
error_log logs/error.log
nginx.conf
Then restart nginx and watch the log file with tail -f logs/error.log as you try to authenticate.
tail -f logs/error.log