Apache服务器提供基本的身份认证技术 ,限定用户访问浏览页面的保密程度

场景:现一有Apache服务器,IP为192.168.152.100。网站主目录在/var/webroot,在网站根目录下有目录auth(即/var/webroot/auth),需要输入用户名和密码才能访问.

产生效果如图:

clip_image001

步骤:

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服务,使用浏览器访问

可以看到结果

clip_image002

完成实验

这是使用用户名和密码的最基本的方式,缺点是,用户和密码是明文传送,所以不安全。