Varnish 3 | X-forwarded-for sometimes not set

David B. haazeloud at gmail.com
Tue Aug 19 11:40:31 CEST 2014


Hi Varnish users,

I'm facing out an issue since several weeks and I can't figure how to 
correct this. :(
I hope someone can explain me what's I'm doing wrong.

Setup is quite simple :
client request an web page though http => varnish (cache or pass) => 
backend (apache)

Sometimes, x-forwarded-for was not set and apache recieve an empty 
x-forwarded-for header.
This trigger an alarm on my monitoring system. Backend must have 
client-ip for legal reason.

This happens only a few times per hour. :(

This morning, theses errors were seen with very large URI.
Perhaps large URI can hit a buffer length and there's no more room space 
left for x-forwarded-for ?
Sometimes, this can happen with short uri as well. :(

Varnishlog extract :
   446 ReqStart     c (client ip here) 63424 998725987
   446 RxRequest    c GET
   446 RxURL        c 
/forums/T2dnUwACAAAAAAAAAACPiNfnAAAAABCLD7gBHgF2b3JiaXMAAAAAAkSsAAD/////APQBAP////+4AU9nZ1MAAAAAAAAAAAAAj4jX5wEAAABuORkUE//q/////////////////////zwDdm9yYmlzDQAAAExhdmY1NS40NC4xMDAJAAAAHwAAAGVuY29kZXI9TGF2YzU1LjY4LjEwMCBsaWJ2b3JiaXMZAAAAdGl0bGU9U3ludGhldGl
   446 RxProtocol   c HTTP/1.1
   446 RxHeader     c Host: www.myhost.com
   446 RxHeader     c Connection: keep-alive
   446 RxHeader     c Accept-Encoding: identity;q=1, *;q=0
   446 RxHeader     c User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 
Safari/537.36 OPR/23.0.1522.75
   446 RxHeader     c Accept: */*
   446 RxHeader     c Referer: http://www.myhost.com/mypage.html
   446 RxHeader     c Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
   446 RxHeader     c Cookie: (some cookie here, not much)
   446 RxHeader     c Range: bytes=0-
   446 VCL_call     c recv pass
   446 VCL_call     c hash
   446 Hash         c 
/forums/T2dnUwACAAAAAAAAAACPiNfnAAAAABCLD7gBHgF2b3JiaXMAAAAAAkSsAAD/////APQBAP////+4AU9nZ1MAAAAAAAAAAAAAj4jX5wEAAABuORkUE//q/////////////////////zwDdm9yYmlzDQAAAExhdmY1NS40NC4xMDAJAAAAHwAAAGVuY29kZXI9TGF2YzU1LjY4LjEwMCBsaWJ2b3JiaXMZAAAAdGl0bGU9U3ludGhldG
   446 Hash         c www.myhost.com
   446 VCL_return   c hash
   446 VCL_call     c pass pass
   446 Backend      c 39 www www3
   446 TTL          c 998725987 RFC -1 -1 -1 1408439635 0 1408439634 0 0
   446 VCL_call     c fetch
   446 TTL          c 998725987 VCL -1 3600 -1 1408439635 -0
   446 TTL          c 998725987 VCL 120 3600 -1 1408439635 -0
   446 VCL_return   c hit_for_pass
   446 ObjProtocol  c HTTP/1.1
   446 ObjResponse  c Request-URI Too Large
   446 ObjHeader    c Date: Tue, 19 Aug 2014 09:13:54 GMT
   446 ObjHeader    c Server: Apache
   446 ObjHeader    c Content-Length: 26
   446 ObjHeader    c Content-Type: text/html; charset=iso-8859-1
   446 VCL_call     c deliver deliver
   446 TxProtocol   c HTTP/1.1
   446 TxStatus     c 414
   446 TxResponse   c Request-URI Too Large
   446 TxHeader     c Content-Type: text/html; charset=iso-8859-1
   446 TxHeader     c Content-Length: 26
   446 TxHeader     c Accept-Ranges: bytes
   446 TxHeader     c Date: Tue, 19 Aug 2014 09:13:54 GMT
   446 TxHeader     c Age: 0
   446 TxHeader     c Connection: keep-alive
   446 TxHeader     c Cache-Control: , no-transform
   446 TxHeader     c X-Cache: MISS
   446 Length       c 26
   446 ReqEnd       c 998725987 1408439634.963270903 
1408439634.964049816 2.867349625 0.000756264 0.000022650

Apache (backend) log extract :
192.168.0.3 - [19/Aug/2014:11:13:54 +0200] "GET 
/forums/T2dnUwACAAAAAAAAAACPiNfnAAAAABCLD7gBHgF2b3JiaXMAAAAAAkSsAAD/////APQBAP////+4AU9nZ1MAAAAAAAAAAAAAj4jX5wEAAABuORkUE//q/////////////////////zwDdm9yYmlzDQAAAExh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AATZoSiwOUGjISgAgJADA4TiW5Xmi6HmiaJqqynEsy/NEURRNU1VVleNolueJoiiapqqqKsvSNM8TRVE0TVVVXWia54miKJqmqrouPM/zRFEUTVNVXRee53miKIqmqaquC1EURdM0TVVVVdcFomiapqmqquq6QBRF0zRVVVVdF4iiKJqmqqqu6wLTNE1VVVXXlV2Aaaqqqrqu6wJUVVVd13VlGaCqquq6rivLANd1XdeVZVkG4Lqu68qyLAAA4MABACDACDrJqLIIG0248AAUGrIiAIgCAACMYUoxpQxjEkIKoWFMQkghZFJSKimlCkIqJZVSQUilpFIySi2lllIFIZWSSqkgpFJSKQUAgB04AIAdWAiFhqwEAPIAAAhjlGKMMeckQkox5pxzEiGlGHPOOakUY84555yUkjHnnHNOSumYc845J6VkzDnnnJNSOuecc85JKaV0zjnnpJRSQugcdFJKKZ1zDkIBAEAFDgAAATaKbE4wElRoyEoAIBUAwOA4lqVpnieKpmlJkqZ5nueJpqpqkqRpnieKpqmqPM/zRFEUTVNVeZ7niaIomqaqcl1RFEXTNE1VJcuiaIqmqaqqC9M0TdNUVdeFaZqmaaqq68K2VVVVXdd1Yduqqqqu68rAdV3XdWUZyK7ruq4sCwAAT3AAACqwYXWEk6KxwEJDVgIAGQAAhDEIKYQQUsggpBBCSCmFkAAAgAEHAIAAE8pAoSErAYBUAACAEGuttdZaaw1j1lprrbXWEuestdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbVWACB2hQPAToQNqyOcFI0FFhqyEgAIBwAAjEGIMegklFJKhRBj0ElIpbUYK4QYg1BKSq21mDznHIRSWmotxuQ55yCk1FqMMSbXQkgppZZii7G4FkIqKbXWYqzJGJVSai22GGvtxaiUSksxxhhrMMbm1FqMMdZaizE6txJLjDHGWoQRxsUWY6y11yKMEbLF0lqttQZjjLG5tdhqzbkYI4yuLbVWa80FAJg8OABAJdg4w0rSWeFocKEhKwGA3A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e3Uu8X9TkXRQQeNUz6MnzRpzPFFzM1wBNJUfHsHRVGKgAKAAAAAsAgx57hqeCxUBIoweOcb/n1n5O5e2kGtInNRjVefe/eT7QQ6HBWg0AAP72nDZ4yxhu9v9iOKlBXHQeekq7aBL+2jwP8AB0Wcbaqz/vcXxRvpy8zfPxWLsfPeKV2MQwDLIBAAAAAAAAAAAAQIKUxaXts46LD/e/2jujM7T" 
414 201 "-" "-"

This is not a "normal" URI for us, but I'm still getting requests like 
theses. :(

OS : Linux Debian

# /usr/sbin/varnishd -V
varnishd (varnish-3.0.5 revision 1a89b1f)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS

varnish deamon command line :
/usr/sbin/varnishd -P /var/run/varnishd.pid -a :80 -T localhost:6082 -f 
/etc/varnish/default.vcl -S /etc/varnish/secret -w 25,2000 -s malloc,28G 
-p thread_pool_add_delay=2 -p thread_pools=2 -p session_linger=100

Varnish default.vcl :
# cat /etc/varnish/default.vcl

acl purge {
     "localhost";
     "192.168.0.0"/24;
}

probe healthcheck {
         .request =
             "GET /up.txt HTTP/1.1"
             "Host: www.myhost.com"
             "Connection: close";
         .timeout = 5s;
         .interval = 30s;
         .window = 10;
         .threshold = 8;
}


backend www2 {
     .host = "192.168.0.2";
     .port = "80";
     .probe = healthcheck;
}

backend www3 {
     .host = "192.168.0.3";
     .port = "80";
     .probe = healthcheck;
}

director www round-robin {
     { .backend = www2; }
     { .backend = www3; }
}

sub vcl_recv {

     if (req.request == "PURGE") {
         if (!client.ip ~ purge) {
             error 405 "Not allowed.";
         }
         return (lookup);
     }

     # X-Forwarded-For
     if (req.http.X-Forwarded-Proto !~ "https")
     {
         remove req.http.X-Forwarded-For;
         set req.http.X-Forwarded-For = client.ip;
     }

     # no cookie
     if (
      req.url == "/favicon.ico" ||
      req.url ~ "^/css/" ||
      req.url ~ "^/fonts/" )
     {
         remove req.http.Cookie;
     }

     if (req.http.host ~ "www.myhost.com$")
     {
         set req.backend = www;
     }

     if (req.http.Authorization || req.http.Cookie)
     {
         return(pass);
     }

     if (req.request != "GET" && req.request != "HEAD")
     {
         return(pass);
     }

     if (req.backend.healthy)
     {
         set req.grace = 30s;
     }
     else
     {
         set req.grace = 1h;
     }

     return (lookup);

}

sub vcl_fetch {

     set beresp.grace = 1h;

     if (beresp.status == 404 && req.restarts == 0)
     {
         return(restart);
     }

     if (beresp.http.X-Esi) {
         set beresp.do_esi = true;
         unset beresp.http.X-Esi;
     }
     return (deliver);
}

sub vcl_hit {
     if (req.request == "PURGE")
     {
         purge;
         error 200 "Purged.";
     }
     return (deliver);
}

sub vcl_miss {
     if (req.request == "PURGE")
     {
         purge;
         error 200 "Purged.";
     }
     return (fetch);
}

sub vcl_pass {

     return(pass);
}

sub vcl_pipe {

     set bereq.http.connection = "close";

     return(pipe);
}

sub vcl_deliver {
     remove resp.http.Via;
     remove resp.http.X-Varnish;
     remove resp.http.Server;
     remove resp.http.X-Powered-By;

     set resp.http.Cache-Control = resp.http.Cache-Control + ", 
no-transform";

     if (obj.hits > 0)
     {
         set resp.http.X-Cache = "HIT";
     }
     else
     {
         set resp.http.X-Cache = "MISS";
     }
     return (deliver);

}

Best Regards
David.




More information about the varnish-misc mailing list