Skip to content

How to configure mod_remoteip

Last updated on 28th June 2021

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

Published inUbuntu

3 Comments

  1. Thank you very much for the information you have given to everyone.
    2 days I read 18 hours a day and nothing, YOU saved me, thanks again!

    • Damien Damien

      Glad I could help!

Leave a Reply

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