Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
Wow, thanks, I totally should have caught onto this one. –  Steven Lu Feb 26 '12 at 23:30
    
Also, if you don't know how to configure Apache to see real IP, read it here: Real IP through Varnish for Apache –  user149170 Dec 11 '12 at 15:28
add comment

Run nginx -V and make sure you have --with-http_realip_module

If so add the following into your /etc/nginx/nginx.conf HTTP head section

set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;

Once done service nginx restart (or /etc/init.d/nginx restart)

This was tested on varnish 3.0.4 and 100% working.

******:varnishd -V
varnishd (varnish-3.0.4 revision 9f83e8f)
share|improve this answer
    
Use 127.0.0.1 if Varnish and NGINX run on the same machine. Otherwise ensure that the ip address you specify is the ip address of the machine that runs Varnish. –  sridhar pandurangiah Apr 4 at 7:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.