如何封鎖Apache HTTP Server層級的IP位址?

瞭解如何在Apache HTTP Server層級封鎖IP位址。 在Apache Web Server的/etc/conf.d資料夾中,以要封鎖的IP建立.conf檔案。

說明 description

環境

Adobe Experience Manager

問題/症狀

我們的網站遭遇拒絕服務攻擊、垃圾郵件或遭駭客攻擊。 如何封鎖Apache HTTP Server (AEM Dispatcher)層級的IP位址?

解決方法 resolution

大部分的Web應用程式防火牆(WAF) (例如模組安全性)都可以封鎖IP位址清單。 不過,如果您正在執行Apache HTTP Server,而且想要立即封鎖IP位址,請遵循下列步驟(不適用於AEM as a Cloud Service)

  1. 在您的伺服器上建立名為block-offending-ips.conf的檔案

  2. 在編輯器中開啟檔案,並新增Location指示詞,以封鎖所有違反規定的IP存取您想要封鎖的URL。 以下檔案的內容有兩個選項:
    A.如果要求是採取代理方式(透過CDN、負載平衡器等),而且遠端使用者的IP僅位於標頭(例如X-Forwarded-For)中,則可以使用此設定。 請注意,如果已設定remoteip_module,則此設定不適用。

    code language-none
    LocationMatch "/.*"
        Order Allow,Deny
        Allow from all
        SetEnvif X-Forwarded-For "10\.42\.137\.123" DenyAccess
        SetEnvif X-Forwarded-For "122\.6\.218\.101" DenyAccess
        #Repeat the "SetEnvlf X-Forwarded-For ..." for each IP you want to block
        Deny from env=DenyAccess
        /LocationMatch
    

    B.或者,如果遠端使用者直接存取Apache,或您正在使用remoteip_module (請參閱下方的 [ 1] )在Apache中擷取及設定它,則您可以直接使用mod_authz_core的 Require 功能(Apache 2.4)。

    code language-none
    LocationMatch "/.*"
        RequireAll
        Require all granted
        Require not ip 10.42.137.123
        Require not ip 122.6.218.101
        #Repeat the "Require not ip ..." for each IP you want to block
        /RequireAll
        /LocationMatch
    

    [ 1] remoteip_module

    code language-none
    # Extract true client IP from header added by load balancer/CDN
        IfModule remotetip module
        # valid for ELB or ELB+CloudFront
        RemoteIPHeader X-Forwarded-For
        IfModule
    
  3. 將block-offending-ips.conf檔案拖放到Apache Web Server的/etc/conf.d資料夾中。

  4. 重新啟動Apache HTTP Server。

recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f