您的位置:首页 > 运维架构 > Apache

Apache的应用四-- 基本身份认证

2010-06-08 23:26 369 查看
Apache服务器提供基本的身份认证技术 ,限定用户访问浏览页面的保密程度
场景:现一有Apache服务器,IP为192.168.152.100。网站主目录在/var/webroot,在网站根目录下有目录auth(即/var/webroot/auth),需要输入用户名和密码才能访问.
产生效果如图:



步骤:
1、检查服务器的IP,是否正确
使用命令
Ifconfig eth0 查看,确认你的IP地址
(若有多块网卡,就直接使用ifconfig命令查看)
2、查看服务器的主目录,并在主目录下建立目录auth 及建立访问测试页面auth.html
# mkdir /var/webroot/auth
# cd /var/webroot/auth
# touch auth.html
# echo "This auth file page, Welcome" > auth.html
3、创建访问用户
假设要使用 user1用户进行访问,密码为123
htpasswd -c /etc/httpd/htpasswd user1
New password:
Re-type new password:
Adding password for user user1
4、编辑配置文件 /etc/httpd/conf/httpd.conf
]# vim /etc/httpd/conf/httpd.conf
修改的内容为:
Listen 80
DocumentRoot "/var/webroot"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/webroot">
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
</Directory>
<Directory "/var/webroot/auth">
DirectoryIndex auth.html
Options Indexes
AllowOverride Authconfig
AuthType Basic
AuthBasicProvider file
AuthUserFile /etc/httpd/htpasswd
AuthName "Please Enter Your Username and Password!!!"
Require user user1
</Directory>
5、重启动httpd服务,使用浏览器访问
可以看到结果



完成实验
这是使用用户名和密码的最基本的方式,缺点是,用户和密码是明文传送,所以不安全。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: