Alright, problem fixed, thanks guys.
It was because of the template whitespace/indents messing up since I was copying from a file into the terminal.
My forum was running ok but last night suddenly it start showing 502 bad gateway.
I was looking for issue but after 5min soon I started nodebb from terminal, it started working. But again it started showing the same 502 bad gateway error.
502 bad gateway is the error that nginx returns when NodeBB isn't running. Try running NodeBB will
./nodebb slog or
./nodebb dev and look for errors. Odds are that it is encountering an error and dying.