访问控制 – Directory目录概要
- 核心配置文件内容
Order deny,allow Deny from all Allow from 127.0.0.1
- curl测试状态码为403则被限制访问了
访问控制
- 打开虚拟主机配置文件
- Order,用来定义顺序,是先deny,还是allow
- 若是先deny,就先执行deny的语句
- 若是先allow,就先执行allow的语句
- 特殊性:
- 不管IP是否匹配到,它都会从头到尾执行完
[root@hf-01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf将代码放在防盗链代码上面,防止冲突Order deny,allow Deny from all Allow from 127.0.0.1
- 创建一个admin目录,并新建一个index.php文件,内容为121212
[root@hf-01 ~]# cd /data/wwwroot/111.com[root@hf-01 111.com]# ls11.png 123.php [root@hf-01 111.com]# mkdir admin/[root@hf-01 111.com]# cd admin/[root@hf-01 admin]# ls[root@hf-01 admin]# touch index.php[root@hf-01 admin]# echo "121212" > index.php[root@hf-01 admin]# lsindex.php[root@hf-01 admin]# cat index.php121212[root@hf-01 admin]# cd ..[root@hf-01 111.com]#
- 检查语法错误,并重新加载配置文件
[root@hf-01 111.com]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[root@hf-01 111.com]# /usr/local/apache2.4/bin/apachectl graceful[root@hf-01 111.com]#
- 限制的原 IP
- curl -x127.0.0.1:80 111.com/admin/index.php -I
- 127.0.0.1是目标 IP ,而要访问的IP,也要使用127.0.0.1去访问,最终就是目标IP和原IP是同一个IP,自己和自己通信,限制IP是 原 IP
- -x指定的是目标IP
[root@hf-01 111.com]# curl -x127.0.0.1:80 111.com/admin/index.php -IHTTP/1.1 200 OKDate: Mon, 25 Dec 2017 23:42:01 GMTServer: Apache/2.4.29 (Unix) PHP/5.6.30X-Powered-By: PHP/5.6.30Content-Type: text/html; charset=UTF-8[root@hf-01 111.com]#
- 在更换目标IP,那么原IP也会跟着变化
[root@hf-01 111.com]# curl -x192.168.74.150:80 111.com/admin/index.php -IHTTP/1.1 403 ForbiddenDate: Mon, 25 Dec 2017 23:47:06 GMTServer: Apache/2.4.29 (Unix) PHP/5.6.30Content-Type: text/html; charset=iso-8859-1[root@hf-01 111.com]#
- 浏览器访问111.com/admin会显示forbidden
- 访问控制是用目录的形式来做的,首先规定一个目录访问到哪里去的(目录必须使用绝对路径),然后是Oerder,控制的对象就是来源IP