Apache 提供兩種層級的 IP 存取控制:
本文提供兩種方式的標準配置語法與 Order Allow,Deny 邏輯解析。

# 放置於欲保護的目錄下
Order Allow,Deny
Allow from all
Deny from 124.114.0.0/16
Deny from 124.115.0.0/16
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,Deny
Allow from all
Deny from 124.114.0.0/16
Deny from 124.115.0.0/16
Order Allow,Deny 邏輯解析Deny 規則。Allow 規則。Allow from all 在最後)。Deny 且不符合後續 Allow → 拒絕存取。Deny 或符合後續 Allow → 允許存取。若需「預設拒絕、僅允許白名單」,改用 Order Deny,Allow 並調整規則順序。
Require all granted
Require not ip 124.114.0.0/16
Require not ip 124.115.0.0/16
Require all granted 替代 Allow from allRequire not ip 替代 Deny from# 重新載入配置
systemctl reload httpd
# 或
apachectl graceful
# 測試被封 IP
curl -I https://server-ip/ # 應回傳 403 Forbidden
MaxMind GeoIP 模組按國家封鎖:Require not env BlockCountryfail2ban 動態封鎖攻擊 IP。依據權限與效能需求選擇 .htaccess 或 httpd.conf,Apache 2.4+ 建議直接使用 Require 新語法。
RedHat Linux 5 ifconfig 指令找不到解決方案:PATH 環境變數缺失 /sbin 路徑
Ubuntu 建立虛擬網卡 (IP Alias) 實現單網卡多 IP:修改 /etc/network/interfaces 完整範例
Linux mount 報錯 "Structure needs cleaning" ?xfs_repair 修復全流程
Linux 禁止內核自動升級:yum 配置排除與命令行參數兩大方案
Linux 使用 SecureCRT 配合 rz/sz (lrzsz) 实现文件上传下载