0

Is it possible to change where Apache sources IPs for the access.log file?

Right now I am getting Cloudflare’s IP as I use them as a proxy to prevent my IP from being exposed. The only issue with this is when Apache returns the visitors IP, it is the IP of a Cloudflare datacenter.

Is it possible that I could change this to be the real IP of the user with PHP or in an Apache Configuration file?

1 Answers1

0

Do not use X-Forwarded-For unless you understand exactly how it works, how to encode the data in your logs and how the resulting data will be interpreted by any software you use against the logs.

This header can be absent, and can be multi-valued. The default behaviour (note that this is not ratified standard) is to append the connecting IP address to any value presented in a request to a proxy in the request to the upstream server. Each entry is separated by a comma then a space - and by default, fields are seperated by a space in the standard log formats available in Apache. So the advice given by Rich will render your log files unreadable by most software.

Cloudflare provide the header CF-Connecting-IP to indicate the address which connected to Cloudflare - and this is the limit of trustworthy resolution about the origin of the request (assuming you trust Cloudflare). If all your traffic comes via Cloudflare, then PHP should see the value in $_SERVER['CF-Connecting-IP'] and you should add this to your Apache log format string as %{CF-Connecting-IP}i

symcbean
  • 47,736
  • 6
  • 59
  • 94