11.26 訪問控制Directory

訪問控制 – Directory目錄概要

  • 核心配置文件內容
<Directory /data/wwwroot/111.com/admin/>
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
  • curl測試狀態碼爲403則被限制訪問了

訪問控制

  1. 打開虛擬主機配置文件
  • Order,用來定義順序,是先deny,仍是allow
    • 如果先deny,就先執行deny的語句
    • 如果先allow,就先執行allow的語句
    • 特殊性:
      • 無論IP是否匹配到,它都會從頭至尾執行完
[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>
  1. 建立一個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]#
  1. 檢查語法錯誤,並從新加載配置文件
[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]#
  1. 限制的原 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]#
  1. 在更換目標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]#
  1. 瀏覽器訪問111.com/admin會顯示forbidden

輸入圖片說明

  • 訪問控制是用目錄的形式來作的,首先規定一個目錄訪問到哪裏去的(目錄必須使用絕對路徑),而後是Oerder,控制的對象就是來源IP
相關文章
相關標籤/搜索