====== 由 Cloudflare 擔任 CDN 設定 log 顯示用戶實際 IP (Apache) ====== * 如果是 Nginx 可以參考 [[nginx_proxy_real_ip]] * 設定環境 : Debian GNU/Linux 10 ===== 設定方式 ===== - 使用 root 權限操作 sudo -i - 啟動 remoteip sa2enmod remoteip - 更新 000-default.conf 設定, 加入 RemoteIPHeader CF-Connecting-IPvi /etc/apache2/sites-available/000-default.conf : # modules, e.g. #LogLevel info ssl:warn RemoteIPHeader CF-Connecting-IP ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are : - 設定 Cloudflare 的 IP vi /etc/apache2/conf-available/remoteip.conf RemoteIPHeader CF-Connecting-IP RemoteIPTrustedProxy 173.245.48.0/20 RemoteIPTrustedProxy 103.21.244.0/22 RemoteIPTrustedProxy 103.22.200.0/22 RemoteIPTrustedProxy 103.31.4.0/22 RemoteIPTrustedProxy 141.101.64.0/18 RemoteIPTrustedProxy 108.162.192.0/18 RemoteIPTrustedProxy 190.93.240.0/20 RemoteIPTrustedProxy 188.114.96.0/20 RemoteIPTrustedProxy 197.234.240.0/22 RemoteIPTrustedProxy 198.41.128.0/17 RemoteIPTrustedProxy 162.158.0.0/15 RemoteIPTrustedProxy 104.16.0.0/12 RemoteIPTrustedProxy 172.64.0.0/13 RemoteIPTrustedProxy 131.0.72.0/22 RemoteIPTrustedProxy 2400:cb00::/32 RemoteIPTrustedProxy 2606:4700::/32 RemoteIPTrustedProxy 2803:f800::/32 RemoteIPTrustedProxy 2405:b500::/32 RemoteIPTrustedProxy 2405:8100::/32 RemoteIPTrustedProxy 2a06:98c0::/29 RemoteIPTrustedProxy 2c0f:f248::/32 - 檢查設定格是是否有異常 apache2ctl configtest - 重新啟動 apache systemctl restart apache2 ===== 參考網址 ===== * https://support.cloudflare.com/hc/en-us/articles/200170786-Restoring-original-visitor-IPs {{tag>Cloudflare proxy realip apache}}