vim /usr/local/nginx/conf/vhost/test.com.conf #添加一个虚拟主机配置文件
添加下面内容
server {
listen 80;
server_name test.com;
index index.html index.htm index.php;
root /data/wwwroot/test.com;
location /admin/ #这里/指定的全部 ~指定单个文件
{
auth_basic "Auth";
auth_basic_user_file /usr/local/ngxin/conf/htpasswd;
autoindex on;
#定义的用户名密码文件,这里需要用htpasswd
}
}
yum -y isntall httpd #安装http
htpasswd -c /usr/local/nginx/conf/htpasswd aaa #设置一个用户为aaa -c只要指定一次就好,如果需要在添加多个用户 不需要指定,这里-c指覆盖
New password: #密码bbb
Re-type new password:
Adding password for user aaa
/usr/local/nginx/sbin/nginx -s reload #重新加载