1.创建用户权限的账号和密码
htpasswd -c /usr/local/nginx/conf/htpasswd aming
2.新建个文件夹 /data/wwwroot/test.com
写入文件内容 echo “test.com” > /data/wwwroot/test.com/index.html
3.编写nginx/conf/vhost
vi test.com.conf
server
{
listen 80;
server_name test.com;
index index.html index.htm index.php
root /data/wwwroot/test.com;
# 用户验证 重启NGINX后生效
location /
{
auth_basic "Auth";
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
}
}
访问如果不输入用户名和密码 报401错误
401 Authorization Required
如果目录没有可执行权限
报403错误
403 Forbidden
可执行chmod 777 test.com