NginX
$ htpasswd -c /var/www/domain.com/admin/.htpasswd username
server {
listen 80;
server_name domain.com www.domain.com;
location / {
# your normal content
}
location /admin {
auth_basic "Administrator Login";
auth_basic_user_file /var/www/domain.com/admin/.htpasswd;
}
#!!! IMPORTANT !!! We need to hide the password file from prying eyes
# This will deny access to any hidden file (beginning with a .period)
location ~ /\. { deny all; }
}