Apache 配置 之 存取控制

來源:互聯網
上載者:User

標籤:存取控制

存取控制的設定:

 假設:在日誌裡發現某個IP 嘗試攻擊我的網站,就可以通過配置把這個IP 封掉。

拷貝模版

vim /usr/local/apache2/conf/httpd.conf

<Directory "/usr/local/apache2/cgi-bin">

    AllowOverride None

    Options None

    Order allow,deny  #Order :誰在前,先執行誰。不分上下,只分前後。

    Allow from all     #允許所有IP

    Deny from 127.0.0.1  # 控制這個IP

</Directory>

[[email protected] ~]# apachectl -t

Syntax OK

[[email protected] ~]# apachectl restart

[[email protected] ~]# curl -x127.0.0.1:80 -I www.test.com

HTTP/1.1 403 Forbidden   #此時訪問不到127.0.0.1

Date: Tue, 27 Sep 2016 12:31:27 GMT

Server: Apache/2.2.31 (Unix) PHP/5.6.24

Content-Type: text/html; charset=iso-8859-1

-------------------------------------------------------------------------------------------

白名單限制,限制指定的IP 訪問。

[[email protected] ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

<filesmatch "(.*)admin(.*)">

         Order Deny,Allow

         Deny from all

         Allow from 127.0.0.1

         

 </filesmatch>

[[email protected] ~]# apachectl -t

Syntax OK

[[email protected] ~]# apachectl restart


[[email protected] ~]# curl -x10.72.4.30:80 -I www.test.com/admin.php

HTTP/1.1 403 Forbidden         #限制成功,403 不能訪問

Date: Tue, 27 Sep 2016 12:46:15 GMT

Server: Apache/2.2.31 (Unix) PHP/5.6.24

Content-Type: text/html; charset=iso-8859-1

---------------------------------------------

[[email protected] ~]# curl -x127.0.0.1:80 -I www.test.com/admin.php

HTTP/1.1 200 OK                # 可以訪問

Date: Tue, 27 Sep 2016 12:48:48 GMT

Server: Apache/2.2.31 (Unix) PHP/5.6.24

X-Powered-By: PHP/5.6.24

Set-Cookie: gfwC_2132_saltkey=IYZYTY7u; expires=Thu, 27-Oct-2016 12:48:48 GMT; Max-Age=2592000; path=/; httponly

Set-Cookie: gfwC_2132_lastvisit=1474976928; expires=Thu, 27-Oct-2016 12:48:48 GMT; Max-Age=2592000; path=/

Set-Cookie: gfwC_2132_sid=POGGLH; expires=Wed, 28-Sep-2016 12:48:48 GMT; Max-Age=86400; path=/

Set-Cookie: gfwC_2132_lastact=1474980528%09admin.php%09; expires=Wed, 28-Sep-2016 12:48:48 GMT; Max-Age=86400; path=/

Cache-Control: max-age=0

Expires: Tue, 27 Sep 2016 12:48:48 GMT

Content-Type: text/html; charset=gbk


本文出自 “CBO#Boy_Linux之路” 部落格,請務必保留此出處http://20151213start.blog.51cto.com/9472657/1857339

Apache 配置 之 存取控制

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.