Apache2.4 獲取Cloudflare真實訪客IP

APACHE2.4只要更改LOG格式就可以

1.remoteip Module   Enable

2.打开的APACHE设置 /etc/apache2/apache2.conf

尋找

#Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.

#Use mod_remoteip instead.

#
LogFormat “%v:%h %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” vhost_combined
LogFormat “%h %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” combined
LogFormat “%h %l %u %t \”%r\” %>s %O” common
LogFormat “%{Referer}i -> %U” referer
LogFormat “%{User-agent}i” agent

把%h替换成%{CF-Connecting-IP}i

最後restart apache