Categories
Tech

Preserve original host IP via Apache reverse proxy using mod_extract_forwarded in CentOS

Using Apache as a reverse proxy can cause difficulty when reviewing backend web server logs. The default Apache server configuration will incorrectly log the reverse proxy host as being the origin IP address, instead of the actual IP that sent the request. Luckily there is a pretty simple fix to this using the Apache module mod_extract_forwarded. Using this module is much simpler and easier to install than using the alternative method using the mod_rpaf module.

This guide focuses on Apache installations running on CentOS, however the configuration will be applicable to other Redhat distros too.

First ensure that you have the EPEL repository installed and configured. See here

Install the mod_extract_forwarded Apache module

sudo yum install mod_extract_forwarded

Edit the mod_extract_forwarded.conf, uncomment the MEFaccept line and replace the sample IP addresses with your own reverse proxy IP.

sudo vi /etc/httpd/conf.d/mod_extract_forwarded.conf

Restart Apache to take effect and verify the module is loaded.

sudo service httpd restart
yum list installed | grep forward