Cloudflare is the most popular service provider as a network provider.
This also includes DNS, DDoS protection and website security.
Cloudflare works as a reverse proxy server.
Once website traffic is routed using the Cloudflare network, the backend server does not know the visitor’s actual IP address.
As a result, you will see the cloudflare IP address in the Apache logs.
Now the question is how to get the real IP of the visitor in the logs, and not the IP Cloudflare.
To solve this problem, cloudflare provides an Apache module to get the real IP addresses of visitors and register them.
This guide will help you enable Apache mod_cloudflare module on Debian system.
It will register the IP address of the real visitor in the Apache access logs.
Installing Apache mod_cloudflare on Debian
Cloudflare provides an official module for Apache server to capture real IP address.
Add GPG – Open Terminal and run the following commands to enable adding the gpg key to your system.
sudo apt install curl
curl -C - https://pkg.cloudflare.com/pubkey.gpg | sudo apt-key add -
Add PPA – then add the cloudflare repository to your debian system
echo "deb https://pkg.cloudflare.com/ `lsb_release -cs` main" | sudo tee /etc/apt/sources.list.d/cloudflare.list
Install the package – then update the Apt cache and install the libapache2-mod-cloudflare package on your Ubuntu system.
sudo apt update
sudo apt install libapache2-mod-cloudflare
Press “Y” to confirm the request during installation.
After the installation is complete, restart the Apache2 service and check the active modules using the following commands.
sudo systemctl restart apache2
It’s all. The Apache server now logs the visitor’s real IP address.
sudo apache2ctl -M