sudo apt-get install apache2-utils sudo htpasswd -c /var/www/ exampleuser

Put the following in your nginx conf file for the given server block you want this to apply to:

auth_basic “Restricted”; auth_basic_user_file /var/www/;

Thanks DO!

Mario Loria is a builder of diverse infrastructure with modern workloads on both bare-metal and cloud platforms. He's traversed roles in system administration, network engineering, and DevOps. You can learn more about him here.