Create a *.htpasswd file. Eg:
touch /etc/nginx/conf.d/nginx.htpasswd
Add an user to the file:
echo -n 'user1' >> ./nginx/nginx.htpasswd
Generate a password to the user using openssl ultility:
openssl passwd -apr1 >> ./nginx/nginx.htpasswd
The above command will prompt