Saat menggunakan Cloudflare sebagai reverse proxy, Anda menemukan access log domain pada webserver tidak mencatat real IP dari visitor melainkan IP dari Cloudflare itu sendiri.
Meski dari Cloudflare sudah menyediakan grafik untuk melihat seberapa banyak visitor pada Analytics & Logs. Namun dengan access log Anda dapat mengetahui lebih detil terkait trafik yang masuk serta dapat digunakan bila ingin membuat dashboard monitor yang dapat Anda disesuaikan.
cPanel #
Install modul remoteip Apache.
yum -y install ea-apache24-mod_remoteip
Untuk konfigurasi remoteip pada domain atau subdomain tertentu maka perlu membuat 2 direktori berikut.
mkdir /etc/apache2/conf.d/userdata/ssl/2_4/username/example.com
mkdir /etc/apache2/conf.d/userdata/std/2_4/username/example.com
Selanjutnya buat file remoteip.conf
pada kedua folder yang telah dibuat dan konfigurasikan seperti berikut.
nano /etc/apache2/conf.d/userdata/ssl/2_4/username/example.com/remoteip.conf
nano /etc/apache2/conf.d/userdata/std/2_4/username/example.com/remoteip.conf
# Update IP Cloudflare dapat dicek melalui https://www.cloudflare.com/ips-v4/
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/13
RemoteIPTrustedProxy 104.24.0.0/14
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22
Rebuild httpd
/scripts/rebuildhttpdconf
Jika output OK, lalu restart service apache.
/scripts/restartsrv_httpd
Jika ingin mengaktifkan remoteip untuk semua domain dan akun cpanel
touch /etc/apache2/conf.d/userdata/remoteip.conf
Selanjutnya edit file seperti langkah sebelumnya.
Apache #
Buat file remoteip.conf
lalu tambahkan konfigurasi berikut.
/etc/httpd/conf.d/remoteip.conf
<IfModule mod_remoteip.c>
# Update IP Cloudflare dapat dicek melalui https://www.cloudflare.com/ips-v4/
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/13
RemoteIPTrustedProxy 104.24.0.0/14
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22
</IfModule>
Selanjutnya edit LogFormat pada file httpd.conf
menjadi
LogFormat "%a %l %u %t \"%r\" %>s %b" common
Restart service Apache
systemctl restart httpd
Nginx #
Buat file remoteip.conf
lalu tambahkan konfigurasi berikut.
nano /etc/nginx/conf.d/remoteip.conf
# Update IP Cloudflare dapat dicek melalui https://www.cloudflare.com/ips-v4/
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
real_ip_header CF-Connecting-IP;
Restart service nginx.
systemctl restart nginx