To set up virtual host password protection in Nginx you can follow such steps:
1. Created .htpassword file outside web server foot folder using commands below:
# echo -n 'user:' >> /var/www/taras/data/.htpasswd # openssl passwd -apr1 >> /var/www/taras/data/.htpasswd
Second command will ask you for a password.
2. Add the following lines to Nginx configuration file /etc/nginx/nginx.conf
auth_basic "Restricted Content"; auth_basic_user_file /var/www/taras/data/.htpasswd;
into virtual host definition section.