Password protect website with nginx and openssl

Generate the htpasswd with openssl:

echo "admin:`openssl passwd -apr1`" | tee -a /etc/nginx/htpasswd.users
Add inside server or location in nginx config:
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
Restart nginx and test.