3.4. Logging a Proxied Client’s IP Address
Problem
You want to log the IP address of the actual client requesting your pages, even if they’re being requested through a proxy.
Solution
None.
Discussion
Unfortunately, the HTTP protocol itself prevents this from being possible. From the client side, proxies are intended to be completely transparent; from the side of the origin server, where the content actually resides, they are meant to be almost utterly opaque, concealing the identity of a request.
Your best option is to log the IP address from which the request came. If it came directly from a browser, it will be the client’s address; if it came through one or more proxy servers, it will be the address of the one that actually contacts your server.
Both the combined and common
log formats include the %h format effector, which represents
the (remote) client’s identity. However, this may be a hostname rather
than an address, depending on the setting of your HostNameLookups directive, among
other things. If you
always want the client’s IP address to be included in your logfile,
use the %a effector
instead.
See Also
The HTTP protocol specification at ftp://ftp.isi.edu/in-notes/rfc2616.txt
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access