If you're trying to use nginx basic auth on a freshly installed Ubuntu server you might find out that you're missing this very important tool, htpasswd. If you're having trouble locating it, don't worry, here is the command you need to run in order to install it.
# apt-get install apache2-utils
If you're not logged in as root add sudo in front of the command and you're done.
Here is an example command for using htpasswd for nginx:
# htpasswd -c -d /path/to/file username