How to configure mod_remoteip
1 min read

How to configure mod_remoteip

How to configure mod_remoteip

If you use Cloudflare or another reverse proxy service you’ve probably noticed that your Apache access logs are only recording Cloudflare IP addresses and not real IP addresses of connecting visitors, Cloudflare used to have their own plugin for older versions of Apache and operating systems though as of Ubuntu 18.04 and Debian 9 they’ve decided to stop supporting the Apache module.

The replacement is a module called “mod_remoteip” which is actually extremely easy to install and configure though it did initially take me hours to figure our how to configure the module correctly.

First step is to enable mod_remoteip

sudo a2enmod remoteip

Once you’ve enabled you then need to open your Apache configuration file.

sudo nano /etc/apache2/apache2.conf

Add the following line at the very bottom of your Apache configuration file

RemoteIPHeader X-Forwarded-For

Now while you still have your Apache configuration file open you need to make one last edit to the line below.

LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

Swap the h to and “a” (without quotation marks), so as below.

LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

That’s it, all you need to do now is restart Apache using the line below and you should begin to see real IP addresses for your visitors in your Apache access logs.

sudo systemctl restart apache2