Cloudflare Apache access_log 127.0.0.1

Running a standard Apache2 website behind a Cloudflare tunnel and I see that any access attempts are logged with:

127.0.0.1 - - [19/May/2026:18:40:18 +0000] "GET / HTTP/1.1" 304 248 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36"

We’ll need to enable apache’s remoteip module, configure our apache site’s conf to include the required cloudflare header, change our apache logformat syntax, and then define the trusted cloudflare proxy IP’s. Sounds harder than it really is, so here are the commands.

Enable the Apache remoteip Module
sudo a2enmod remoteip

Update your apache site conf file
nano /etc/apache2/sites-available/000-default.conf

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName my.awesome.server
RemoteIPHeader CF-Connecting-IP
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Update the Apache LogFormat Syntax
nano /etc/apache2/apache2.conf
Search for LogFormat “%h %l %u %t “%r” %>s %O “%{Referer}i” “%{User-Agent}i”” combined
Replace with LogFormat “%a %l %u %t “%r” %>s %O “%{Referer}i” “%{User-Agent}i”” combined

Create Remote IP Trusted Proxy File
nano /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/13
RemoteIPTrustedProxy 104.24.0.0/14
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22

You can grab the updated list from https://www.cloudflare.com/ips-v4/# or https://cloudflare.com/ips/

Test Apache Configuration
sudo apache2ctl configtest

Restart Apache Services
sudo apache2ctl restart

Leave a Reply

Your email address will not be published. Required fields are marked *