- Install apache utils
sudo apt-get install apache2-utils
- Add user
sudo htpasswd -c /etc/nginx/.htpasswd foobar
- Enter password when prompted.
Edit nginx configuration for your site in/etc/nginx/sites-enabled/
:server { listen 80; server_name .example.com; # globally set basic auth for server name auth_basic "Restricted"; #For Basic Auth auth_basic_user_file /etc/nginx/.htpasswd; #Basic Auth }
- Reload nginx configuration:
sudo service nginx reload