Install Apache Utils:

 sudo apt-get install apache2-utils

Create a user with a password:

sudo htpasswd -c /etc/nginx/.htpasswd USERNAME

Edit /etc/nginx/sites-available/example.conf

...
  location / {
      
      ...
      auth_basic "Restricted Page";                   
      auth_basic_user_file /etc/nginx/.htpasswd;
  }
...

Reload Nginx

sudo service nginx reload