1、安装httpd-tools
yum install -y httpd-tools
2、设置账号密码
htpasswd -cb /opt/nginx/conf/htpasswd admin 123456
3、配置密码访问
location / {
auth_basic "请输入账号与密码";
auth_basic_user_file /opt/nginx/conf/htpasswd_admin;
root html;
index index.html index.htm;
}
4、重启服务
nginx -s reload