创建用户认证数据文件
[root@www ~]# cd /usr/local/apache/bin/
[root@www bin]# ./htpasswd -c /usr/local/apache/conf/user zhangsan
备注:-c 表示新建用户数据文件;
默认时表示指定的用户数据文件已存在,实际用于添加新的用户或修改现有用户;
回车,给zhangsan设置好密码;
[root@www bin]# cat /usr/local/apache/conf/user
主配置文件添加用户授权配置
[root@www bin]# vim /usr/local/apache/conf/httpd.conf
<Directory "/usr/local/apache/cgi-bin">
......
</Directory>
# 此位置加<Directory></Directory>标签里入如下内容
<Directory "/var/www/html/test">
AuthName "nihao!"
AuthType "Basic"
AuthUserFile /usr/local/apache/conf/user
Require valid-user
</Directory>
<IfModule ssl_module>
......
</IfModule>
# 在配置文件末尾,设置虚拟目录的根目录,/test为虚拟目录的的名称
Alias /test /var/www/html/test
验证用户访问授权
[root@www bin]# mkdir -p /var/www/html/test
[root@www bin]# echo “
This is vdir test
“ > /var/www/html/test/index.html[root@www bin]# service httpd restart