I don't understand: you say you want to protect a subdomain, but your examples show a folder.
Anyways, I'll explain the basics, I think you'll be able to solve your issue once you understand what you'll be doing.
First you need to create a
.htpasswd file. I suggest it to be in
printf "$HTPASSWDUSER:$(openssl passwd -crypt $HTPASSWDPASS 2> /dev/null)\n" >> /var/www/sub.domain.com/conf/nginx/.htpasswd
Now I suggest you to create a file named
/var/www/sub.domain.com/conf/nginx with the following content:
auth_basic "Restricted Area"
You should test configuration in order to avoid errors, and reload Nginx:
nginx -t && service nginx reload