第一步 生成认证文件
print "test:$(openssl passwd -crypt 123456)\n" >>/home/httppwd
第二步 到你使用的web服务器的配置文件内 开启auth_basic认证
这里用的nginx
server{
listen 80;
server_name www.xxx.com xxx.com;
index index.html index.php;
root /home/www/root/www.xxx.com;
location /
{
auth_basic "Please input your username and password!";
auth_basic_user_file /home/htpasswd;
}
}
保存后 检查一下语法是否正确 nginx -t
重启nginx systemctl restart nginx