Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Apache 安全加固 12 步驟:隱藏版本、最小權限、關閉模組、啟用 mod_security

編輯:關於伺服器

聲明:安全無絕對,以下建議可顯著降低風險,請依環境評估效能影響,自行承擔風險。

  1. 套用最新修補程式:未修補的系統,後續防護皆無意義。
  2. 隱藏版本與敏感資訊:
    ServerSignature Off
    ServerTokens Prod
    回應標頭僅顯示 Server: Apache,不洩露版本、OS、模組清單。
  3. 以專屬帳號/群組運行:
    User apache
    Group apache
    避免與其他服務(如郵件伺服器)共用 nobody 導致橫向攻擊。
  4. 限制 Web 根目錄外存取:
    <Directory />
    Order Deny,Allow
    Deny from all
    Options None
    AllowOverride None
    </Directory>
    <Directory /web>
    Order Allow,Deny
    Allow from all
    </Directory>
    需逐目錄明確開啟 Options/Override。
  5. 關閉目錄瀏覽:Options -Indexes
  6. 關閉 SSI (Includes):Options -Includes
  7. 關閉 CGI 執行:Options -ExecCGI(若不使用 CGI)
  8. 禁止跟隨符號連結:Options -FollowSymLinks
  9. 一次關閉多項 Options:Options None 或 Options -ExecCGI -FollowSymLinks -Indexes
  10. 關閉 .htaccess 支援:AllowOverride None
    若需覆寫功能,改用非標準檔名(如 .httpdoverride)並封鎖所有 .ht* 檔案下載:
    AccessFileName .httpdoverride
    <Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
    </Files>
  11. 部署 mod_security:Ivan Ristic 開發的強力 WAF 模組,提供:
    簡易過濾、正則過濾、URL/Unicode 編碼驗證、稽核記錄、空位元組攻擊防禦、上傳限制、伺服器身分隱藏、內建 Chroot 支援等。
  12. 停用非必要模組:編輯 httpd.conf,在 LoadModule 行前加 # 註解。常見可停用:
    mod_imap, mod_include, mod_info, mod_userdir, mod_status, mod_cgi, mod_autoindex
    查詢當前載入:grep LoadModule httpd.conf
Copyright © Windows教程網 All Rights Reserved