实验须知:html
实验主机:192.168.1.11node
1. 配置httpd基于用户的访问控制----basic认证机制web
(1)安装httpd程序,并启动服务vim
#yum install httpd–y [root@node1 ~]# servicehttpd start Starting httpd:httpd: Could not reliably determine the server's fully qualified domain name,using 172.16.33.1 for ServerName [ OK ] [root@node1 ~]# ss –tnl
(2)在配置文件中定义安全域浏览器
(a)修改’MainServer’的路径为/data/web/html,并进行访问测试安全
#vim/etc/httpd/conf/httpd.conf …………. DocumentRoot "/data/web/html" .…….. # mkdir/data/web/html -pv [root@node1 ~]# cd/data/web/html/ [root@node1 html]#vim index.html 添加: <h1>new path</h1> [root@node1 ~]# httpd -t httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName Syntax OK [root@node1 ~]# servicehttpd reload Reloading httpd:
在浏览器中输入:http://192.168.1.11/,访问测试bash
(b)在/data/web/html/添加一个目录employee,并封装Directory,实现对此目录认证basic机制的实现,认证用户tom,jerrydom
# mkdir/data/web/html/employee # cd/data/web/html/employee [root@node1 employee]# vimindex.html Tom 21 Jerry 90 #vim/etc/httpd/conf/httpd.conf ………添加Directory,对目录的访问控制………… <Directory "/data/web/html/employee"> Options None AllowOverride None AuthType basic AuthName "it is only foremployee!!" AuthUserFile /etc/httpd/users/.htpasswd Require user tom jerry </Directory> ……………. [root@node1 html]# httpd-t httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName Syntax OK
(3)建立/etc/httpd/users目录,并在目录下提供用户的帐号文件ide
[root@node1 html]# mkdir/etc/httpd/users [root@node1 html]# cd/etc/httpd/users [root@node1 users]#htpasswd -c -m /etc/httpd/users/.htpasswd tom New password: Re-type new password: Adding password for usertom [root@node1 users]#htpasswd -m /etc/httpd/users/.htpasswdjerry New password: Re-type new password: Adding password for userjerry [root@node1 users]# cat/etc/httpd/users/.htpasswd tom:$apr1$snf79TuR$lX7b.Y8S9bbRtZh8cpbaz1 jerry:$apr1$sxqJzSiW$fa0WXYi2dFdCDIkO.0yCt1 (4)重启服务,并在浏览器进行测试 [root@node1 employee]# httpd-t httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName Syntax OK [root@node1 employee]#service httpd reload Reloading httpd:
此时在浏览器中输入:http://192.168.1.11/employee/,输入tom、jerry及对应密码,屡次输入观察结果;发现只有tom、jerry用户且都要输入正确的密码才能成功访问!测试
2. 基于组的认证
建立组文件,并在配置文件中添加便可。
[root@node1 employee]# vim /etc/httpd/conf/httpd.conf …………修改成以下内容…………….. <Directory"/data/web/html/employee"> Options None AllowOverride None AuthType basic AuthName "it is only foremployee!!" AuthUserFile /etc/httpd/users/.htpasswd AuthUserFile /etc/httpd/users/.htgroup Require group mc </Directory> …………………………. [root@node1 employee]# vim/etc/httpd/users/.htgroup ………….添加以下内容………………. mc: tom jerry [root@node1 employee]#httpd -t httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName Syntax OK [root@node1 employee]#service httpd reload Reloading httpd:
基于组认证的配置就完成了,下面在浏览器中进行访问测试便可!!!!