Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client IP address incorrect. How to set x-forwarded-for in Varnish 4? #24

Open
kindnation opened this issue May 5, 2015 · 4 comments
Open

Comments

@kindnation
Copy link

When I use this Varnish default.vcl, it shows my nginx webserver's IP for the client's IP address. Can you add the X-Forwarded-For and client.ip so that Varnish sends the correct client IP?

@Oyabi
Copy link
Contributor

Oyabi commented May 8, 2015

Add these lines in your /etc/nginx/nginx.conf :

set_real_ip_from   127.0.0.1; #Put the Ip of your varnish/proxy here
real_ip_header      X-Forwarded-For; #Put the Header that your varnish/proxy set

Source : http://linuxaria.com/article/how-to-log-the-correct-ip-having-varnish-and-nginx

@kindnation
Copy link
Author

Oyabi,

I already have that in my nginx.conf. I also have CloudFlare and have added all their proxies to the set_real_ip_from. The client's IP information is correct when I remove Varnish, and send from CloudFlare directly to Nginx. Only when I add Varnish, it seems that it is removing the X-Forwarded-For for the client's IP.

@Oyabi
Copy link
Contributor

Oyabi commented May 14, 2015

I doesn't use CloudFare so it's will be difficult for me.
Have you try this ? https://support.cloudflare.com/hc/en-us/articles/200169376-Can-I-use-CloudFlare-and-Varnish-together-
More interressant here : https://danielmiessler.com/blog/getting-real-ip-addresses-using-cloudflare-nginx-and-varnish/

Tell me if one of these solution works for you. =)

@rajnetgen
Copy link

Hi Kindnation,
for cloudflare add following to your nginx.conf

set_real_ip_from 127.0.0.1; #Put the Ip of your varnish/proxy here
real_ip_header CF-Connecting-IP;

This will then restore correct visitor ip in nginx logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants