實驗須知: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:
基於組認證的配置就完成了,下面在瀏覽器中進行訪問測試便可!!!!