HTTP的访问控制

前提:
安装Apache httpd服务,分别在默认站点目录/var/www/html/下创建并编辑index.html和mkdir 后的/var/www/html/authdir新站点下创建并编辑index.html

试验目的:
只允许192.168.1.1访问www.tarena.com
允许所有用户访问www.tarena.com/authdir/index.html
步骤:
(1)修改站点目录
[root@localhost ~]# mkdir /var/www/html/authdir //创建新站点目录
[root@localhost ~]#vim /var/www/html/authdir/index.html
<html>
<head><title>This is a test Page!!!</title>
<body>
<h1>This is http://www.tarena.com/authdir/index.html!!!</h1&gt;
</body>
</html>

[root@localhost ~]#vim /var/www/html/authdir/index.html //默认站点目录
<html>
<head><title>This is a test Page!!!</title>
<body>
<h1>This is http://www.tarena.com/authdir/index.html!!!</h1&gt;
</body>
</html>
(2)修改主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
...
306 <Directory "/var/www/html">
...
332 Order allow,deny
333 # Allow from all
334 Allow from 192.168.10.5
...
337 <Directory "/var/www/html/authdir">
338 Order allow,deny
339 Allow from all
340 </Directory>
(3)启动服务
[root@localhost ~]# service httpd restart
(4)在不同客户端测试
A:访问/var/www/html/index.html

        用Win 7客户端(IP 192.168.1.1)来访问

HTTP的访问控制
用Linux客户端(IP 192.168.1.2)来访问
HTTP的访问控制
B:访问/var/www/html/authdir/index.html
用Win 7客户端(IP 192.168.1.1)来访问
HTTP的访问控制
用Linux 客户端(IP 192.168.1.2)来访问
HTTP的访问控制
总体访问控制设置成功!!!
补充:
在服务器上查看登录错误日志
root@localhost ~]# tail /var/log/httpd/tarena.com-error_log
HTTP的访问控制

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章