訪問控制 – Directory目錄概要
<Directory /data/wwwroot/111.com/admin/>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
訪問控制
- 打開虛擬主機配置文件
- Order,用來定義順序,是先deny,仍是allow
- 如果先deny,就先執行deny的語句
- 如果先allow,就先執行allow的語句
- 特殊性:
[root@hf-01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
將代碼放在防盜鏈代碼上面,防止衝突
<Directory /data/wwwroot/111.com/admin/>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
- 建立一個admin目錄,並新建一個index.php文件,內容爲121212
[root@hf-01 ~]# cd /data/wwwroot/111.com
[root@hf-01 111.com]# ls
11.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]# ls
index.php
[root@hf-01 admin]# cat index.php
121212
[root@hf-01 admin]# cd ..
[root@hf-01 111.com]#
- 檢查語法錯誤,並從新加載配置文件
[root@hf-01 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax 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 -I
HTTP/1.1 200 OK
Date: Mon, 25 Dec 2017 23:42:01 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
X-Powered-By: PHP/5.6.30
Content-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 -I
HTTP/1.1 403 Forbidden
Date: Mon, 25 Dec 2017 23:47:06 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
[root@hf-01 111.com]#
- 瀏覽器訪問111.com/admin會顯示forbidden

- 訪問控制是用目錄的形式來作的,首先規定一個目錄訪問到哪裏去的(目錄必須使用絕對路徑),而後是Oerder,控制的對象就是來源IP