Learn how to install mod_remoteip and log your visitor’s original IP address at your Apache origin server.
Overview
Cloudflare no longer updates and supports mod_cloudflare. However, if you are using an Apache web server with an operating system such as Ubuntu Server 18.04 and Debian 9 Stretch, you can use mod_remoteip to log your visitor’s original IP address.
Installing mod_remoteip
As this module was created by an outside party, we can't provide technical support for issues related to the plugin.
To install mod_remoteip on your Apache web server:
1. Enable mod_remoteip by issuing the following command:
sudo a2enmod remoteip2. Update the site configuration to include RemoteIPHeader CF-Connecting-IP, e.g.
/etc/apache2/sites-available/000-default.conf
3. Update combined LogFormat entry inServerAdmin [email protected] DocumentRoot /var/www/html ServerName remoteip.andy.support RemoteIPHeader CF-Connecting-IP ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
apache.conf
, replacing %h with %a in /etc/apache2/apache2.conf.
For example, if your current LogFormat appeared as follows:
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combinedyou would update LogFormat to the following:
LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined4. Define trusted proxy addresses by creating
/etc/apache2/conf-available/remoteip.conf
by entering the following code and Cloudflare IPs:
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::/325. Test Apache configuration:
sudo apache2ctl configtest Syntax OK6. Restart Apache:
sudo systemctl restart apache2
FAQs
- Apache won't pass CF-Connecting-IP down the stack. For example, phpinfo will not return this header at all whilst our edge will send it to Apache: type: embedded-entry-inline id: 6lULLteG7NLt9IOsoyBkYo
Related Resources
- mod_remoteip Apache documentation
- Restoring original visitor IPs - Option 1: Installing mod_cloudflare
- Restoring original visitor IPs - Logging visitor IP addresses with mod_cloudflare
- Cloudflare IPs