4.配置用于身份验证的文件,输入以下蓝色内容
[root@localhost public]# vim .htaccess
authuserfile /public/.htpasswd
authtype basic
authname "please input your name 和 密码"
require valid-user
5.创建验证的用户名
[root@localhost public]# htpasswd -c .htpasswd user1
New password:
Re-type new password:
Adding password for user user1
#第一次使用时一定要加上 -c ,以后使用不能在用-c如果 使用的话会把以前的user1覆盖掉。
[root@localhost public]# htpasswd .htpasswd user2 ß第二次创建验证用户就不需要添加-c了
New password:
Re-type new password:
Adding password for user user2
6.查看添加的验证用户,他们都保存在.htpasswdl里面
[root@localhost public ]# tail .htpasswd
user1:8y1Ih7vHL67Sw
user2:617IkejdoO9iw
配置完以后记得重启服务
[root@localhost httpd]# service httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
7.下面开始测试:
设置测试机的ip地址为 192.168.1.30
输入服务器的ip地址192.168.10.25
可以看到 输入用户名和密码就能进去了
8.使用其他的ip地址访问可以看到不提示登陆界面
而是欢迎界面。这就说明访问不到。