Instal apache utils and create.htpasswd file:
sudo apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd [exampleuser]
Add this two lines inside location /
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
Reload nginx
nginx -s reload
or
service nginx restart