If you want to log the actual client IP address, you need to extract the X-Forward-For
header from the request and in order to do that, you need to make a tiny edit in your httpd.conf
file.
- Go to
/etc/apache2/conf
or/etc/httpd/conf
and openhttpd.conf
file. - Search for the string that starts with:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
. - Modify the
%h
to%{X-Forwarded-For}i
. Now, it should look like this:LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
. - Test the config to ensure that there are no typos by typing:
apachectl configtest
. - Save and restart the service by typing:
systemctl restart httpd
orsystemctl restart apache2
. - In your terminal, type
tail -f /var/log/httpd/access.log
and you'll be seeing the client IP being logged in your logs.
Hope you found this tip useful!