1. 生成密码文件

# cd /etc/nginx/passwd
[root@web01 passwd]# htpasswd -c test.pass admin
New password: 
Re-type new password: 
Adding password for user admin
[root@web01 passwd]# ll
total 4
-rw-r--r-- 1 root root 20 Aug 23 08:58 test.pass

2.配置nginx,server段

auth_basic "basic";
auth_basic_user_file /etc/nginx/passwd/test.pass;

3.重启nginx

/etc/init.d/nginx restart

4.验证

nginx登录验证_nginx登录验证