varnish are not sending real (client) ip to apache.

21 views
Skip to first unread message

Mrugesh Shah

unread,
Sep 10, 2015, 10:40:31 AM9/10/15
to vg...@googlegroups.com
Hello,

I have configured varnish + apache + cloudflare. I have configured website to get the IP location and serve the location based website.
e.g. If the apache get the IP from UK the UK website will open on client system.

I have set up the varnish to forward IP in default.vcl as below.

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.
        if (req.http.cf-connecting-ip) {
#        set req.http.X-Forwarded-For = req.http.cf-connecting-ip;
#         } else {
            set req.http.X-Forwarded-For = client.ip;
        }

It would be better for me If anyone can help to solve this.
--
Thanks & Regards,
Mrugesh C Shah

Chintan Mehta

unread,
Sep 14, 2015, 5:42:18 AM9/14/15
to VGLUG
Hello Mrugesh,

You can use one of the sample code below which we use and it's in working state.

********************************************
sub vcl_recv {
    if (req.restarts == 0) {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =
            req.http.X-Forwarded-For + ", " + client.ip;
        } else {
            set req.http.X-Forwarded-For = client.ip;
        }
    }
******************************************** 

Regards,

Chintan Mehta

Director & Co-founder

11, Aryan Corporate Park, Nr. Shilaj Railway Crossing, Thaltej, Ahmedabad, Gujarat, INDIA

Mobile : +91 98255 00947

Skype/Gtalk/YM : chintanm1985

Email : chi...@knowarth.com

Web : www.knowarth.com


Reply all
Reply to author
Forward
0 new messages