Varnish X-Forward-IP

varnish

I currently have a configuration setup of the following:

Load Balancer to
Varnish Caches (x2 servers) to
Web Nodes (x3 servers) (Apache, PHP)

I currently have set req.http.X-Forwarded-For = client.ip in Varnish, which should pass along the IP address to the Apache nodes. The Apache nodes also run mod_rpaf which should help the server use the X-Forward-IP instead of the Varnish cache IPs.

This part is fine for me, but I'm running into a different issue. Currently, only the load balancer is receiving the requests and asking Varnish caches for the pages. Meaning that Apache only logs the IP address of the Load Balancer. However, the load balancer also sends an X-Forwarded-For header in the request to Varnish. How can I pass this header along to the Apache servers?

Best Answer

If you're just interested in the "real" client IP, then take the req.http.X-Forwarded-For = client.ip setting out of Varnish completely.

Varnish will then have no interaction with the header - it should then pass the header as set by the load balancer through to Apache, allowing Apache to see and log the "real" client IP.