How to properly configure grace on Varnish 3.0 - varnish

I'm trying to configure Varnish to keep into cache for 1 minute a 3rd party page (proxied from a service not under my control).
Unluckily this service sometimes can be down and this transfers troubles to my site; to prevent this I want also to serve from the local cache when the service is not available.
I followed tips from grace and saint mode.
Follow some snippets from my VCL file.
Backend configuration:
backend external {
.host = "external.acme.com";
.port = "80";
.probe = {
.url = "/page";
.interval = 5s;
.timeout = 5s;
.window = 1;
.threshold = 1;
}
}
vcl_recv:
sub vcl_recv {
set req.backend = my_backend;
...
# redirect onto 3rd part service
if (req.url ~ "www.acme.com:80/page$") {
set req.url = regsub(req.url, "(.*)", "http://external.acme.com/page");
set req.backend = external;
}
if (!req.backend.healthy) {
set req.grace = 2h;
} else {
set req.grace = 10s;
}
...
vcl_fetch:
sub vcl_fetch {
if (beresp.status == 503) {
set beresp.saintmode = 5s;
#set beresp.ttl = 1h;
return (restart);
}
set beresp.grace = 2h;
set beresp.ttl = 2h;
if (req.http.host == "external.acme.com") {
set beresp.http.X-Varnish-Action = "Caching external.acme.com";
set beresp.ttl = 1m;
return(deliver);
}
I'm testing the down of the remote service by using iptables and the configuration is working:
Proxy of the remote page is OK
Health polling of the 3rp party page is OK
My only issue is that: when I shutdown the remote service, the 3rd party page is served by the cache for not more than one minute (the TTL configured in vcl_fetch) which is a good TTL for when the remote page is available... but I want to continue to serve this for much longer (2 hours).
This seems in contrast with what I read there: http://book.varnish-software.com/3.0/Saving_a_request.html#req-grace-and-beresp-grace
My suspect is that I'm not entering the grace mode, but the only reason I found on documentation is on not configured health check, but If I look into varnishlog I see health check running properly ("Still healthy", "Went sick", ...)
What I'm missing? There's a way to get what I need?
varnishlog traces
This log when all is going well (the remote server is up and running):
0 Backend_health - external Still healthy 4--X-RH 1 1 1 0.010659 0.010557 HTTP/1.1 200 OK
12 BackendClose - external
12 BackendOpen b external ...
12 TxRequest b GET
12 TxURL b ...
12 TxProtocol b HTTP/1.1
12 TxHeader b Cache-Control: max-age=0
12 TxHeader b Upgrade-Insecure-Requests: 1
12 TxHeader b User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
12 TxHeader b Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
12 TxHeader b Accept-Encoding: gzip, deflate, sdch, br
12 TxHeader b Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2
12 TxHeader b Cookie:...
12 TxHeader b If-None-Match: "6338e-4c0f-54429328f4d3d"
12 TxHeader b If-Modified-Since: Wed, 21 Dec 2016 11:10:16 GMT
12 TxHeader b Via: 1.1 ...
12 TxHeader b X-Forwarded-For: ...
12 TxHeader b X-Forwarded-Host: ...
12 TxHeader b X-Forwarded-Server: ...
12 TxHeader b host: ...
12 TxHeader b X-Varnish: 1305584183
12 RxProtocol b HTTP/1.1
12 RxStatus b 304
12 RxResponse b Not Modified
12 RxHeader b Date: Thu, 22 Dec 2016 09:25:21 GMT
12 RxHeader b Server: Apache/2.2.22 (Debian)
12 RxHeader b ETag: "6338e-4c0f-54429328f4d3d"
12 RxHeader b Vary: Accept-Encoding
12 Fetch_Body b 0(none) cls 0 mklen 0
12 Length b 0
12 BackendReuse b external
3 SessionOpen c ::1 60278 :6081
3 ReqStart c ::1 60278 1305584183
3 RxRequest c GET
3 RxURL c /VirtualHostBase/...
3 RxProtocol c HTTP/1.1
3 RxHeader c Host: localhost:6081
3 RxHeader c Cache-Control: max-age=0
3 RxHeader c Upgrade-Insecure-Requests: 1
3 RxHeader c User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
3 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
3 RxHeader c Accept-Encoding: gzip, deflate, sdch, br
3 RxHeader c Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2
3 RxHeader c Cookie:...
3 RxHeader c If-None-Match: "6338e-4c0f-54429328f4d3d"
3 RxHeader c If-Modified-Since: Wed, 21 Dec 2016 11:10:16 GMT
3 RxHeader c Via: 1.1 ...
3 RxHeader c X-Forwarded-For: ...
3 RxHeader c X-Forwarded-Host: ...
3 RxHeader c X-Forwarded-Server: ...
3 RxHeader c Connection: Keep-Alive
3 VCL_call c recv pass
3 VCL_call c hash
3 Hash c http://...
3 Hash c ...
3 VCL_return c hash
3 VCL_call c pass pass
3 Backend c 12 external external
3 TTL c 1305584183 RFC -1 -1 -1 1482398514 0 1482398721 0 0
3 VCL_call c fetch
3 TTL c 1305584183 VCL -1 7200 -1 1482398514 -0
3 TTL c 1305584183 VCL 7200 7200 -1 1482398514 -0
3 TTL c 1305584183 VCL 60 7200 -1 1482398514 -0
3 VCL_return c deliver
3 ObjProtocol c HTTP/1.1
3 ObjResponse c Not Modified
3 ObjHeader c Date: Thu, 22 Dec 2016 09:25:21 GMT
3 ObjHeader c Server: Apache/2.2.22 (Debian)
3 ObjHeader c ETag: "6338e-4c0f-54429328f4d3d"
3 ObjHeader c Vary: Accept-Encoding
3 ObjHeader c X-Varnish-Action: Caching external.acme.com
3 VCL_call c deliver deliver
3 TxProtocol c HTTP/1.1
3 TxStatus c 304
3 TxResponse c Not Modified
3 TxHeader c Server: Apache/2.2.22 (Debian)
3 TxHeader c ETag: "6338e-4c0f-54429328f4d3d"
3 TxHeader c Vary: Accept-Encoding
3 TxHeader c X-Varnish-Action: Caching external.acme.com
3 TxHeader c Accept-Ranges: bytes
3 TxHeader c Date: Thu, 22 Dec 2016 09:21:53 GMT
3 TxHeader c X-Varnish: 1305584183
3 TxHeader c Age: 0
3 TxHeader c Via: 1.1 varnish
3 TxHeader c Connection: keep-alive
3 Length c 0
3 ReqEnd c 1305584183 1482398513.625868082 1482398513.630025387 0.000263691 0.004073620 0.000083685
3 SessionClose c EOF
3 StatSess c ::1 60278 0 1 1 0 1 1 290 0
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482398514 1.0
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482398517 1.0
0 Backend_health - external Still healthy 4--X-RH 1 1 1 0.010621 0.010573 HTTP/1.1 200 OK
This is what I log when the remote goes down (but I still get the cached content as TTL has not been reached):
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482398997 1.0
0 Backend_health - external Went sick ------- 0 1 1 0.000000 0.010652
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482399000 1.0
3 SessionOpen c ::1 60382 :6081
3 ReqStart c ::1 60382 1305584190
3 RxRequest c GET
3 RxURL c /VirtualHostBase/https/...
3 RxProtocol c HTTP/1.1
3 RxHeader c Host: localhost:6081
3 RxHeader c Pragma: no-cache
3 RxHeader c Cache-Control: no-cache
3 RxHeader c Upgrade-Insecure-Requests: 1
3 RxHeader c User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
3 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
3 RxHeader c Accept-Encoding: gzip, deflate, sdch, br
3 RxHeader c Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2
3 RxHeader c Cookie: ...
3 RxHeader c Via: 1.1 ...
3 RxHeader c X-Forwarded-For: ...
3 RxHeader c X-Forwarded-Host: ...
3 RxHeader c X-Forwarded-Server: ...
3 RxHeader c Connection: Keep-Alive
3 VCL_call c recv lookup
3 VCL_call c hash
3 Hash c http://...
3 Hash c ...
3 VCL_return c hash
3 Hit c 1305584185
3 VCL_call c hit deliver
3 VCL_call c deliver deliver
3 TxProtocol c HTTP/1.1
3 TxStatus c 200
3 TxResponse c OK
3 TxHeader c Server: Apache/2.2.22 (Debian)
3 TxHeader c Access-Control-Allow-Origin: *
3 TxHeader c Last-Modified: Wed, 21 Dec 2016 11:10:16 GMT
3 TxHeader c ETag: "6338e-4c0f-54429328f4d3d"
3 TxHeader c Vary: Accept-Encoding
3 TxHeader c Content-Encoding: gzip
3 TxHeader c Content-Type: text/html
3 TxHeader c X-Varnish-Action: Caching external.acme.com
3 TxHeader c Content-Length: 4367
3 TxHeader c Accept-Ranges: bytes
3 TxHeader c Date: Thu, 22 Dec 2016 09:30:03 GMT
3 TxHeader c X-Varnish: 1305584190 1305584185
3 TxHeader c Age: 39
3 TxHeader c Via: 1.1 varnish
3 TxHeader c Connection: keep-alive
3 Length c 4367
3 ReqEnd c 1305584190 1482399003.173985004 1482399003.174190044 0.000112534 0.000087976 0.000117064
3 SessionClose c EOF
3 StatSess c ::1 60382 0 1 1 0 0 0 441 4367
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482399003 1.0
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482399006 1.0
And finally this the error I get after TTL over (after more than a minute)
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482399282 1.0
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482399285 1.0
12 SessionOpen c ::1 60412 :6081
12 ReqStart c ::1 60412 1305584191
12 RxRequest c GET
12 RxURL c /VirtualHostBase/https/...
12 RxProtocol c HTTP/1.1
12 RxHeader c Host: localhost:6081
12 RxHeader c Cache-Control: max-age=0
12 RxHeader c Upgrade-Insecure-Requests: 1
12 RxHeader c User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
12 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
12 RxHeader c Accept-Encoding: gzip, deflate, sdch, br
12 RxHeader c Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2
12 RxHeader c Cookie: ...
12 RxHeader c If-None-Match: "6338e-4c0f-54429328f4d3d"
12 RxHeader c If-Modified-Since: Wed, 21 Dec 2016 11:10:16 GMT
12 RxHeader c Via: 1.1 ...
12 RxHeader c X-Forwarded-For: ...
12 RxHeader c X-Forwarded-Host: ...
12 RxHeader c X-Forwarded-Server: ...
12 RxHeader c Connection: Keep-Alive
12 VCL_call c recv pass
12 VCL_call c hash
12 Hash c http://...
12 Hash c ...
12 VCL_return c hash
12 VCL_call c pass pass
12 FetchError c no backend connection
12 VCL_call c error deliver
12 VCL_call c deliver deliver
12 TxProtocol c HTTP/1.1
12 TxStatus c 503
12 TxResponse c Service Unavailable
12 TxHeader c Server: Varnish
12 TxHeader c Content-Type: text/html; charset=utf-8
12 TxHeader c Retry-After: 5
12 TxHeader c Content-Length: 419
12 TxHeader c Accept-Ranges: bytes
12 TxHeader c Date: Thu, 22 Dec 2016 09:34:48 GMT
12 TxHeader c X-Varnish: 1305584191
12 TxHeader c Age: 0
12 TxHeader c Via: 1.1 varnish
12 TxHeader c Connection: close
12 Length c 419
12 ReqEnd c 1305584191 1482399288.281390190 1482399288.281631470 0.000269890 0.000148058 0.000093222
12 SessionClose c error
12 StatSess c ::1 60412 0 1 1 0 1 0 257 419
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482399288 1.0
0 Backend_health - external Still sick ------- 0 1 1 0.000000 0.010652
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1482399291 1.0

I believe your problem lies on the line return (restart); in vcl_fetch. The restart will force Varnish to process the request from the beginning with a different backend, as you don't have another one this will raise an error. This is the cause that your object is served from the cache for not more than its TTL.
This would be the correct flow:
TTL valid => deliver from cache;
TTL invalid => try to fetch from backend;
Backend not responding => use grace TTL;
Grace TTL valid => deliver from staled cache;
The restart is changing this flow by not letting Varnish get to step 4. Try removing it and see the magic happen.

Related

AttributeError: object has no attribute 'published' when parsing CNN source

I'm facing this problem since parsing CNN.RSS site. It only get first 7 entries then i get this problem. Below it my log .. Please help me :(. Thanks you
This is my code:
import feedparser
url = "http://rss.cnn.com/rss/edition.rss"
feed = feedparser.parse(url)
for news in feed.entries:
print(news.published)
Log
My log:
https://pastebin.com/vMJSXD0J
To debug this you should first check if published is a part of the keys for news or not.
>>> news.keys()
dict_keys(['title', 'title_detail', 'summary', 'summary_detail', 'links', 'link', 'id', 'guidislink', 'published', 'published_parsed', 'media_content'])
According to this published is a part of the keys for news so your code should work which actually does work.
>>> import feedparser
>>> url = "http://rss.cnn.com/rss/edition.rss"
>>> feed = feedparser.parse(url)
>>> for news in feed.entries:
print(news.published)
Thu, 11 Mar 2021 04:53:36 GMT
Thu, 11 Mar 2021 03:21:32 GMT
Wed, 10 Mar 2021 12:54:12 GMT
Thu, 11 Mar 2021 05:13:03 GMT
Wed, 10 Mar 2021 23:46:07 GMT
Wed, 10 Mar 2021 17:56:03 GMT
Thu, 11 Mar 2021 05:50:56 GMT
Thu, 11 Mar 2021 00:37:19 GMT
Thu, 11 Mar 2021 04:44:57 GMT
Wed, 10 Mar 2021 03:46:09 GMT
Wed, 10 Mar 2021 13:24:02 GMT
Thu, 11 Mar 2021 05:37:44 GMT
Thu, 11 Mar 2021 01:48:41 GMT
Wed, 10 Mar 2021 17:13:52 GMT
Thu, 11 Mar 2021 03:43:19 GMT
Thu, 11 Mar 2021 05:11:13 GMT
'
'
etc
PS - This is implemented on Python 3.9

elasticdump : dump ended with error (get phase) => Error: conn ect ECONNREFUSED MY_IP:PORT

When i used localhost as IP-address it worked as expected
C:\Users\Lenovo>elasticdump --input=http://localhost:9200/wellnessservices --out
put=http://192.168.2.87:9200/wellnessservices --type=mapping
Tue, 10 Jan 2017 09:56:47 GMT | starting dump
Tue, 10 Jan 2017 09:56:47 GMT | got 1 objects from source elasticsearch (offset:
0)
Tue, 10 Jan 2017 09:56:47 GMT | sent 1 objects to destination elasticsearch, wro
te 1
Tue, 10 Jan 2017 09:56:47 GMT | got 0 objects from source elasticsearch (offset:
1)
Tue, 10 Jan 2017 09:56:47 GMT | Total Writes: 1
Tue, 10 Jan 2017 09:56:47 GMT | dump complete
But when i specify the IP-address for the same localhost then i am getting error as shown below
C:\Users\Lenovo>elasticdump --input=http://192.168.2.83:9200/wellnessservices --
output=http://192.168.2.87:9200/wellnessservices --type=mapping
Tue, 10 Jan 2017 10:02:51 GMT | starting dump
Tue, 10 Jan 2017 10:02:52 GMT | Error Emitted => connect ECONNREFUSED 192.168.2.
83:9200
Tue, 10 Jan 2017 10:02:52 GMT | Total Writes: 0
Tue, 10 Jan 2017 10:02:52 GMT | dump ended with error (get phase) => Error: conn
ect ECONNREFUSED 192.168.2.83:9200
I am having the same problem. It shouldn't be the problem with socket, because I added --maxSockets=5 in the command.
Fri, 20 Jan 2017 20:32:53 GMT | Error Emitted => connect ECONNREFUSED <IP>
Fri, 20 Jan 2017 20:32:53 GMT | Total Writes: 166700
Fri, 20 Jan 2017 20:32:53 GMT | dump ended with error (set phase) => Error: connect ECONNREFUSED <IP>

Can Google´s cloud-monitor cause performance issues?

I think i have a Problem with Googles Cloud Monitoring.
It fires apprx. 20 log per Second and my Server has a big performance problem.
I used varnishlog and varnishncsa to view the logs.
Is there a way to stop the process which is fireing or to deactivate the Cloud Monitoring?
11 Debug c herding
11 SessionClose c timeout
11 StatSess c 173.245.xxx.xxx 312312 1 1 18 0 0 0 7398 4158
17 Debug c herding
17 Interrupted c ReqStart
17 ReqStart c 173.245.xxx.xxx 50606 123123123123
17 RxRequest c GET
17 RxURL c /
17 RxProtocol c HTTP/1.1
17 RxHeader c Host: mydomain.com
17 RxHeader c Connection: Keep-Alive
17 RxHeader c Accept-Encoding: gzip
17 RxHeader c CF-IPCountry: NL
17 RxHeader c X-Forwarded-For: 5.153.xxx.xxx
17 RxHeader c CF-RAY: 1cffb07cf1df00e2-AMS
17 RxHeader c X-Forwarded-Proto: https
17 RxHeader c CF-Visitor: {"scheme":"https"}
17 RxHeader c Cookie: __cfduid=d3208fd678d1fad8234c234c234c234c2
17 RxHeader c Accept: */*
17 RxHeader c User-Agent: Stackdriver_terminus_bot(http://www.stackdriver.com)
17 RxHeader c CF-Connecting-IP: xxx.xxx.xxx.xxx
17 VCL_call c recv lookup
17 VCL_call c hash
17 Hash c /
17 Hash c mydomain.tld
17 VCL_return c hash
17 Hit c 1123123123123
17 VCL_call c hit deliver
17 VCL_call c deliver deliver
17 TxProtocol c HTTP/1.1
17 TxStatus c 302
17 TxResponse c Found
17 TxHeader c Server: Apache/2.2.22 (Debian)
17 TxHeader c Location: https://mydomain.tld/
17 TxHeader c Cache-Control: max-age=3600
17 TxHeader c Expires: Wed, 01 Apr 2015 00:03:26 GMT
17 TxHeader c Vary: Accept-Encoding
17 TxHeader c Content-Encoding: gzip
17 TxHeader c Content-Type: text/html; charset=iso-8859-1
17 TxHeader c Content-Length: 231
17 TxHeader c Accept-Ranges: bytes
17 TxHeader c Date: Tue, 31 Mar 2015 23:03:45 GMT
17 TxHeader c X-Varnish: 123123123 123123123
17 TxHeader c Age: 19
17 TxHeader c Via: 1.1 varnish
17 TxHeader c Connection: keep-alive
17 Length c 231
17 ReqEnd c 123123123 1427843025.446457863 1427843025.446561337 0.084021330 0.000043869 0.000059605
and
xxx.xxx.xxx.xxx - - [31/Mar/2015:22:48:53 +0000] "GET http://mydomain.tld/ HTTP/1.1" 302 231 "-" "Stackdriver_terminus_bot(http://www.stackdriver.com)"
All IP´s are xx´ed and i changed my domainname of course..
I hope Cloud Monitoring doesn't cause issue performance but... it's still in beta :)
From here I know that for use Cloud Monitoring you have installed an agent: I think is a daemon and if you are on Debian based you can stop it from classic /etc/init.d or simple you can unistall with apt-get remove stackdriver-agent command.
Hope this help

How to ignore spree redirects in varnish?

I am using varnish on a RoR application. I am getting a redirect loop on the "forgot password" link. I suspect that this is happening due to spree gem (backend). How can I ignore redirects from spree in varnish?
Following is my vcl:
# This is a basic VCL configuration file for varnish. See the vcl(7)
import std;
import geoip;
backend back1 {
.host = "localhost";
.port = "81";
.connect_timeout = 5s;
.first_byte_timeout = 10s;
.between_bytes_timeout = 10s;
.probe = {
.url = "/";
.interval = 5s;
.timeout = 10s;
.window = 5;
.threshold = 3;
}
}
backend back2 {
.host = "localhost";
.port = "81";
.connect_timeout = 5s;
.first_byte_timeout = 10s;
.between_bytes_timeout = 10s;
.probe = {
.url = "/";
.interval = 5s;
.timeout = 10s;
.window = 5;
.threshold = 3;
}
}
acl purge {
"localhost";
}
director voylla_ms round-robin {
{
.backend = back1;
}
{
.backend = back2;
}
}
sub vcl_recv {
set req.backend = voylla_ms;
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;
}
##getting the country code from client IP using geoip
# set req.http.X-GeoIP = geoip.country(""+"192.189.54.254");
}
if (req.http.Cookie ~ "vy0ln") {
return(pass);
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
## changes made for purging
if(req.request == "PURGE"){
if(!client.ip ~ purge){
error 405 "Not Allowed!";
}
return (lookup);
}
if ((req.url ~ "^/account") || (req.url ~ "^/user") || (req.url ~ "^/login#") || (req.url ~ "^/orders") || (req.url ~ "^/checkout") || (req.url ~ "^/cod") || (req.url ~ "^/cart") || (req.url ~ "^/online_payment") || (req.url ~ "^/wishlists" ) || (req.url ~ "^/admin") || (req.url ~ "^/email_to_friend/") || (req.http.host ~ "payu") || (req.url ~ "^/call_me")){
return (pass);
}
if ((req.url == "/") || (req.url ~ "^/t/") || (req.url ~ "^/designers") || req.url ~ "^/taxons/" || (req.url ~ "\.(css|js|png|gif|jpeg|jpg|swf|html|ico|txt)$") || (req.url ~ "^/products/") || (req.url ~ "^/ql/") || (req.url ~ "search") || (req.url ~ "^/policy") || (req.url ~ "^/help") || (req.url ~ "^/media") || (req.url ~ "^/about") || (req.url ~ "^/contact") || (req.url ~ "^/career")){
std.syslog(180, "should be cached: " + req.http.host + req.url);
return (lookup);
} else {
std.syslog(180, "should not be cached: "+req.http.host+req.url);
return (pass);
}
if (req.http.Authorization) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}
sub vcl_fetch {
std.syslog(180, "request cookie is" + req.http.Cookie);
if (req.http.Cookie ~ "vy0ln") {
return (deliver);
}
if (req.url ~ "^/taxons/sold_out_status.") {
std.syslog(180, "setting TTL for sold out products");
set beresp.do_esi = true;
set beresp.ttl = 1s;
return(deliver);
}
if ((req.url ~ "^/account") || (req.url ~ "^/user") || (req.url ~ "^/login") || (req.url ~ "^/orders") || (req.url ~ "^/checkout") || (req.url ~ "^/cod") || (req.url ~ "^/cart") || (req.url ~ "^/online_payment") || (req.url ~ "^/wishlists" ) || (req.url ~ "^/admin") || (req.url ~ "^/email_to_friend/") || (req.http.host ~ "payu") || (req.url ~ "^/call_me"))
{
return (deliver);
}
if ((req.url == "/") || (req.url ~ "^/t/") || (req.url ~ "^/designers") || req.url ~ "^/taxons/" || (req.url ~ "\.(css|js|png|gif|jpeg|jpg|swf|html|ico|txt)$") || (req.url ~ "^/products/") || (req.url ~ "^/ql/") || (req.url ~ "search") || (req.url ~ "^/policy") || (req.url ~ "^/help") || (req.url ~ "^/media") || (req.url ~ "^/about") || (req.url ~ "^/contact") || (req.url ~ "^/career")) {
std.syslog(180, "fetched: " + req.http.host + req.url);
if (req.url ~ "^/taxons/") {
set beresp.ttl = 3600s;
} else {
set beresp.ttl = 86400s;
}
set beresp.http.X-Cacheable = "YES";
set beresp.http.Cache-Control = "public";
return (deliver);
} else {
std.syslog(180, "a pass: " + req.http.host + req.url);
return (deliver);
}
# this section of code sets the API to return a response code of 200 not 302. DO NOT MODIFY OR DELETE COULD MESS UP CLIENTS.
if(beresp.status == 302 && !beresp.http.Location){
set beresp.status = 200;
set beresp.response = "OK";
}
}
sub vcl_error {
# std.syslog(180, "inside vcl_error")
return (deliver);
}
sub vcl_miss {
std.syslog(180, "inside vcl_miss");
if (req.request == "PURGE"){
purge;
}
return (fetch);
}
sub vcl_hit {
std.syslog(180, "inside vcl_hit");
if(req.request == "PURGE"){
purge;
}
return (deliver);
}
sub vcl_deliver {
std.syslog(180, "inside vcl_deliver");
std.syslog(180, "response cookie is " + resp.http.Cookie);
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
return (deliver);
}
sub vcl_hash {
hash_data(req.url);
hash_data(req.http.X-Forwarded-Proto);
return(hash);
# if (req.http.host) {
# hash_data(req.http.host);
# } else {
# hash_data(server.ip);
# }
# return (hash);
}
Following is the output of varnishlog:
4 TxHeader c X-Runtime: 0.007428
4 TxHeader c X-Rack-Cache: miss
4 TxHeader c Vary: Accept-Encoding
4 TxHeader c Content-Encoding: gzip
4 TxHeader c Content-Length: 117
4 TxHeader c Accept-Ranges: bytes
4 TxHeader c Date: Wed, 30 Oct 2013 12:03:25 GMT
4 TxHeader c X-Varnish: 1346509087
4 TxHeader c Age: 0
4 TxHeader c Via: 1.1 varnish
4 TxHeader c Connection: keep-alive
4 TxHeader c X-Cache: MISS
4 Length c 117
4 ReqEnd c 1346509087 1383134605.871565104 1383134605.884164095 0.198731184 0.012528181 0.000070810
4 Debug c herding
4 Interrupted c ReqStart
12 TxRequest b GET
12 TxURL b /user/password/new
12 TxProtocol b HTTP/1.1
12 TxHeader b host: beta.voylla.com
12 TxHeader b Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
12 TxHeader b Accept-Encoding: gzip,deflate,sdch
12 TxHeader b Accept-Language: en-US,en;q=0.8
12 TxHeader b Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
12 TxHeader b User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
12 TxHeader b X-Forwarded-Port: 80
12 TxHeader b X-Forwarded-Proto: http
12 TxHeader b X-Forwarded-For: 122.167.116.196, 10.130.85.29
12 TxHeader b X-Varnish: 1346509088
12 RxProtocol b HTTP/1.1
12 RxStatus b 301
12 RxResponse b Moved Permanently
12 RxHeader b Server: nginx/1.4.1
12 RxHeader b Date: Wed, 30 Oct 2013 12:03:26 GMT
12 RxHeader b Content-Type: text/html; charset=utf-8
12 RxHeader b Transfer-Encoding: chunked
12 RxHeader b Connection: keep-alive
12 RxHeader b Status: 301 Moved Permanently
12 RxHeader b Location: https://beta.voylla.com/user/password/new
12 RxHeader b X-UA-Compatible: IE=Edge,chrome=1
12 RxHeader b Cache-Control: no-cache, private
12 RxHeader b Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
12 RxHeader b X-Runtime: 0.003554
12 RxHeader b X-Rack-Cache: miss
12 RxHeader b Vary: Accept-Encoding
12 RxHeader b Content-Encoding: gzip
12 Fetch_Body b 3(chunked) cls 0 mklen 1
12 Length b 118
12 BackendReuse b back1
4 ReqStart c 10.130.85.29 25877 1346509088
4 RxRequest c GET
4 RxURL c /user/password/new
4 RxProtocol c HTTP/1.1
4 RxHeader c host: beta.voylla.com
4 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
4 RxHeader c Accept-Encoding: gzip,deflate,sdch
4 RxHeader c Accept-Language: en-US,en;q=0.8
4 RxHeader c Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
4 RxHeader c User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
4 RxHeader c X-Forwarded-For: 122.167.116.196
4 RxHeader c X-Forwarded-Port: 80
4 RxHeader c X-Forwarded-Proto: http
4 RxHeader c Connection: keep-alive
4 VCL_call c recv pass
4 VCL_call c hash
4 Hash c /user/password/new
4 Hash c http
4 VCL_return c hash
4 VCL_call c pass pass
4 Backend c 12 voylla_ms back1
4 TTL c 1346509088 RFC 120 -1 -1 1383134606 0 1383134606 0 0
4 VCL_call c fetch deliver
4 ObjProtocol c HTTP/1.1
4 ObjResponse c Moved Permanently
4 ObjHeader c Server: nginx/1.4.1
4 ObjHeader c Date: Wed, 30 Oct 2013 12:03:26 GMT
4 ObjHeader c Content-Type: text/html; charset=utf-8
4 ObjHeader c Status: 301 Moved Permanently
4 ObjHeader c Location: https://beta.voylla.com/user/password/new
4 ObjHeader c X-UA-Compatible: IE=Edge,chrome=1
4 ObjHeader c Cache-Control: no-cache, private
4 ObjHeader c Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
4 ObjHeader c X-Runtime: 0.003554
4 ObjHeader c X-Rack-Cache: miss
4 ObjHeader c Vary: Accept-Encoding
4 ObjHeader c Content-Encoding: gzip
4 Gzip c u F - 118 107 80 864 874
4 VCL_call c deliver deliver
4 TxProtocol c HTTP/1.1
4 TxStatus c 301
4 TxResponse c Moved Permanently
4 TxHeader c Server: nginx/1.4.1
4 TxHeader c Content-Type: text/html; charset=utf-8
4 TxHeader c Status: 301 Moved Permanently
4 TxHeader c Location: https://beta.voylla.com/user/password/new
4 TxHeader c X-UA-Compatible: IE=Edge,chrome=1
4 TxHeader c Cache-Control: no-cache, private
4 TxHeader c Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
4 TxHeader c X-Runtime: 0.003554
4 TxHeader c X-Rack-Cache: miss
4 TxHeader c Vary: Accept-Encoding
4 TxHeader c Content-Encoding: gzip
4 TxHeader c Content-Length: 118
4 TxHeader c Accept-Ranges: bytes
4 TxHeader c Date: Wed, 30 Oct 2013 12:03:26 GMT
4 TxHeader c X-Varnish: 1346509088
4 TxHeader c Age: 0
4 TxHeader c Via: 1.1 varnish
4 TxHeader c Connection: keep-alive
4 TxHeader c X-Cache: MISS
4 Length c 118
4 ReqEnd c 1346509088 1383134606.141532421 1383134606.273408175 0.257368326 0.131802797 0.000072956
4 Debug c herding
4 Interrupted c ReqStart
15 TxRequest b GET
15 TxURL b /user/password/new
15 TxProtocol b HTTP/1.1
15 TxHeader b host: beta.voylla.com
15 TxHeader b Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
15 TxHeader b Accept-Encoding: gzip,deflate,sdch
15 TxHeader b Accept-Language: en-US,en;q=0.8
15 TxHeader b Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
15 TxHeader b User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
15 TxHeader b X-Forwarded-Port: 443
15 TxHeader b X-Forwarded-Proto: https
15 TxHeader b X-Forwarded-For: 122.167.116.196, 10.130.85.29
15 TxHeader b X-Varnish: 1346509089
15 RxProtocol b HTTP/1.1
15 RxStatus b 302
15 RxResponse b Found
15 RxHeader b Server: nginx/1.4.1
15 RxHeader b Date: Wed, 30 Oct 2013 12:03:26 GMT
15 RxHeader b Content-Type: text/html; charset=utf-8
15 RxHeader b Transfer-Encoding: chunked
15 RxHeader b Connection: keep-alive
15 RxHeader b Status: 302 Found
15 RxHeader b Location: http://beta.voylla.com/user/password/new
15 RxHeader b X-UA-Compatible: IE=Edge,chrome=1
15 RxHeader b Cache-Control: no-cache, private
15 RxHeader b Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
15 RxHeader b X-Runtime: 0.003107
15 RxHeader b X-Rack-Cache: miss
15 RxHeader b Vary: Accept-Encoding
15 RxHeader b Content-Encoding: gzip
15 Fetch_Body b 3(chunked) cls 0 mklen 1
15 Length b 117
15 BackendReuse b back2
4 ReqStart c 10.130.85.29 25877 1346509089
4 RxRequest c GET
4 RxURL c /user/password/new
4 RxProtocol c HTTP/1.1
4 RxHeader c host: beta.voylla.com
4 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
4 RxHeader c Accept-Encoding: gzip,deflate,sdch
4 RxHeader c Accept-Language: en-US,en;q=0.8
4 RxHeader c Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
4 RxHeader c User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
4 RxHeader c X-Forwarded-For: 122.167.116.196
4 RxHeader c X-Forwarded-Port: 443
4 RxHeader c X-Forwarded-Proto: https
4 RxHeader c Connection: keep-alive
4 VCL_call c recv pass
4 VCL_call c hash
4 Hash c /user/password/new
4 Hash c https
4 VCL_return c hash
4 VCL_call c pass pass
4 Backend c 15 voylla_ms back2
4 TTL c 1346509089 RFC 120 -1 -1 1383134607 0 1383134606 0 0
4 VCL_call c fetch deliver
4 ObjProtocol c HTTP/1.1
4 ObjResponse c Found
4 ObjHeader c Server: nginx/1.4.1
4 ObjHeader c Date: Wed, 30 Oct 2013 12:03:26 GMT
4 ObjHeader c Content-Type: text/html; charset=utf-8
4 ObjHeader c Status: 302 Found
4 ObjHeader c Location: http://beta.voylla.com/user/password/new
4 ObjHeader c X-UA-Compatible: IE=Edge,chrome=1
4 ObjHeader c Cache-Control: no-cache, private
4 ObjHeader c Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
4 ObjHeader c X-Runtime: 0.003107
4 ObjHeader c X-Rack-Cache: miss
4 ObjHeader c Vary: Accept-Encoding
4 ObjHeader c Content-Encoding: gzip
4 Gzip c u F - 117 106 80 856 866
4 VCL_call c deliver deliver
4 TxProtocol c HTTP/1.1
4 TxStatus c 302
4 TxResponse c Found
4 TxHeader c Server: nginx/1.4.1
4 TxHeader c Content-Type: text/html; charset=utf-8
4 TxHeader c Status: 302 Found
4 TxHeader c Location: http://beta.voylla.com/user/password/new
4 TxHeader c X-UA-Compatible: IE=Edge,chrome=1
4 TxHeader c Cache-Control: no-cache, private
4 TxHeader c Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
4 TxHeader c X-Runtime: 0.003107
4 TxHeader c X-Rack-Cache: miss
4 TxHeader c Vary: Accept-Encoding
4 TxHeader c Content-Encoding: gzip
4 TxHeader c Content-Length: 117
4 TxHeader c Accept-Ranges: bytes
4 TxHeader c Date: Wed, 30 Oct 2013 12:03:26 GMT
4 TxHeader c X-Varnish: 1346509089
4 TxHeader c Age: 0
4 TxHeader c Via: 1.1 varnish
4 TxHeader c Connection: keep-alive
4 TxHeader c X-Cache: MISS
4 Length c 117
4 ReqEnd c 1346509089 1383134606.471671820 1383134606.628998280 0.198263645 0.157256603 0.000069857
0 Backend_health - back1 Still healthy 4--X-RH 5 3 5 0.757326 0.264340 HTTP/1.1 200 OK
4 Debug c herding
4 Interrupted c ReqStart
12 TxRequest b GET
12 TxURL b /user/password/new
12 TxProtocol b HTTP/1.1
12 TxHeader b host: beta.voylla.com
12 TxHeader b Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
12 TxHeader b Accept-Encoding: gzip,deflate,sdch
12 TxHeader b Accept-Language: en-US,en;q=0.8
12 TxHeader b Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
12 TxHeader b User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
12 TxHeader b X-Forwarded-Port: 80
12 TxHeader b X-Forwarded-Proto: http
12 TxHeader b X-Forwarded-For: 122.167.116.196, 10.130.85.29
12 TxHeader b X-Varnish: 1346509090
12 RxProtocol b HTTP/1.1
12 RxStatus b 301
12 RxResponse b Moved Permanently
12 RxHeader b Server: nginx/1.4.1
12 RxHeader b Date: Wed, 30 Oct 2013 12:03:26 GMT
12 RxHeader b Content-Type: text/html; charset=utf-8
12 RxHeader b Transfer-Encoding: chunked
12 RxHeader b Connection: keep-alive
12 RxHeader b Status: 301 Moved Permanently
12 RxHeader b Location: https://beta.voylla.com/user/password/new
12 RxHeader b X-UA-Compatible: IE=Edge,chrome=1
12 RxHeader b Cache-Control: no-cache, private
12 RxHeader b Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
12 RxHeader b X-Runtime: 0.002530
12 RxHeader b X-Rack-Cache: miss
12 RxHeader b Vary: Accept-Encoding
12 RxHeader b Content-Encoding: gzip
12 Fetch_Body b 3(chunked) cls 0 mklen 1
12 Length b 118
12 BackendReuse b back1
4 ReqStart c 10.130.85.29 25877 1346509090
4 RxRequest c GET
4 RxURL c /user/password/new
4 RxProtocol c HTTP/1.1
4 RxHeader c host: beta.voylla.com
4 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
4 RxHeader c Accept-Encoding: gzip,deflate,sdch
4 RxHeader c Accept-Language: en-US,en;q=0.8
4 RxHeader c Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
4 RxHeader c User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
4 RxHeader c X-Forwarded-For: 122.167.116.196
4 RxHeader c X-Forwarded-Port: 80
4 RxHeader c X-Forwarded-Proto: http
4 RxHeader c Connection: keep-alive
4 VCL_call c recv pass
4 VCL_call c hash
4 Hash c /user/password/new
4 Hash c http
4 VCL_return c hash
4 VCL_call c pass pass
4 Backend c 12 voylla_ms back1
4 TTL c 1346509090 RFC 120 -1 -1 1383134607 0 1383134606 0 0
4 VCL_call c fetch deliver
4 ObjProtocol c HTTP/1.1
4 ObjResponse c Moved Permanently
4 ObjHeader c Server: nginx/1.4.1
4 ObjHeader c Date: Wed, 30 Oct 2013 12:03:26 GMT
4 ObjHeader c Content-Type: text/html; charset=utf-8
4 ObjHeader c Status: 301 Moved Permanently
4 ObjHeader c Location: https://beta.voylla.com/user/password/new
4 ObjHeader c X-UA-Compatible: IE=Edge,chrome=1
4 ObjHeader c Cache-Control: no-cache, private
4 ObjHeader c Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
4 ObjHeader c X-Runtime: 0.002530
4 ObjHeader c X-Rack-Cache: miss
4 ObjHeader c Vary: Accept-Encoding
4 ObjHeader c Content-Encoding: gzip
4 Gzip c u F - 118 107 80 864 874
4 VCL_call c deliver deliver
4 TxProtocol c HTTP/1.1
4 TxStatus c 301
4 TxResponse c Moved Permanently
4 TxHeader c Server: nginx/1.4.1
4 TxHeader c Content-Type: text/html; charset=utf-8
4 TxHeader c Status: 301 Moved Permanently
4 TxHeader c Location: https://beta.voylla.com/user/password/new
4 TxHeader c X-UA-Compatible: IE=Edge,chrome=1
4 TxHeader c Cache-Control: no-cache, private
4 TxHeader c Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
4 TxHeader c X-Runtime: 0.002530
4 TxHeader c X-Rack-Cache: miss
4 TxHeader c Vary: Accept-Encoding
4 TxHeader c Content-Encoding: gzip
4 TxHeader c Content-Length: 118
4 TxHeader c Accept-Ranges: bytes
4 TxHeader c Date: Wed, 30 Oct 2013 12:03:26 GMT
4 TxHeader c X-Varnish: 1346509090
4 TxHeader c Age: 0
4 TxHeader c Via: 1.1 varnish
4 TxHeader c Connection: keep-alive
4 TxHeader c X-Cache: MISS
4 Length c 118
4 ReqEnd c 1346509090 1383134606.831753492 1383134606.841119766 0.202755213 0.009296179 0.000070095
4 Debug c herding
4 Interrupted c ReqStart
15 TxRequest b GET
15 TxURL b /user/password/new
15 TxProtocol b HTTP/1.1
15 TxHeader b host: beta.voylla.com
15 TxHeader b Accept: te xt/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
15 TxHeader b Accept-Encoding: gzip,deflate,sdch
15 TxHeader b Accept-Language: en-US,en;q=0.8
15 TxHeader b Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
15 TxHeader b User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
15 TxHeader b X-Forwarded-Port: 443
15 TxHeader b X-Forwarded-Proto: https
15 TxHeader b X-Forwarded-For: 122.167.116.196, 10.130.85.29
15 TxHeader b X-Varnish: 1346509091
15 RxProtocol b HTTP/1.1
15 RxStatus b 302
15 RxResponse b Found
15 RxHeader b Server: nginx/1.4.1
15 RxHeader b Date: Wed, 30 Oct 2013 12:03:26 GMT
15 RxHeader b Content-Type: text/html; charset=utf-8
15 RxHeader b Transfer-Encoding: chunked
15 RxHeader b Connection: keep-alive
15 RxHeader b Status: 302 Found
15 RxHeader b Location: http://beta.voylla.com/user/password/new
15 RxHeader b X-UA-Compatible: IE=Edge,chrome=1
15 RxHeader b Cache-Control: no-cache, private
15 RxHeader b Set-Cookie: _voylla.com_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWExYjc1ZDM2ZTczMzc4OGIyNTgyYmNjZGE3ZjIxOGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTJvb0ZReTEya05ocWlNTXlMN2RsYkNlQ2ZXYjZtVzdHODd2a24rbjVxOXM9BjsARg%3D%3D--ae5f33cd9559daf7cf84a22640aa69e9e0ae95d9;
15 RxHeader b X-Runtime: 0.007156
15 RxHeader b X-Rack-Cache: miss
15 RxHeader b Vary: Accept-Encoding
15 RxHeader b Content-Encoding: gzip
15 Fetch_Body b 3(chunked) cls 0 mklen 1
15 Length b 117
15 BackendReuse b back2
4 ReqStart c 10.130.85.29 25877 1346509091
4 RxRequest c GET
4 RxURL c /user/password/new
4 RxProtocol c HTTP/1.1
4 RxHeader c host: beta.voylla.com
4 RxHeader c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
4 RxHeader c Accept-Encoding: gzip,deflate,sdch
4 RxHeader c Accept-Language: en-US,en;q=0.8
4 RxHeader c Cookie: rv4=1060512134; rv3=1060513775; rv2=1060513789; rv1=1060512380; __atuvc=2%7C42%2C4%7C43; __utma=8135733.481193715.1382614910.1382966468.1383133459.6; __utmb=8135733.1.10.1383133459; __utmc=8135733; __utmz=8135733.1382614910.1.1.utmcsr=(direct)|utm
You can catch the redirect code on vcl_fetch:
sub vcl_fetch {
// ..
if (beresp.status == 307 &&
/* TO-DO: verify that this work better than 'req.url ~ "imagecache"' */
beresp.http.Location == req.url &&
beresp.ttl > 5s) {
set beresp.ttl = 5s;
set beresp.http.cache-control = "max-age=5";
}
// ..
}
You can see it in context on https://github.com/NITEMAN/varnish-bites/blob/master/varnish3/drupal-base.vcl

varnish serve old object during refresh

How can I serve an old object during the fetch of an expired object or max
out connection?
I¹ve configured the grace period in both the vcl_recv as the vcl_fetch.
I even tried to use the saint mode to give me back an ³old² cached object.
Can somebody give me help in this matter?
sub vcl_recv {
# Purge through http
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
ban("req.url ~ " + req.url );
error 200 "Purged.";
}
# Unset all cookies available
if (req.http.cookie) {
unset req.http.cookie;
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
# Adding Grace period in case backend lags
set req.grace = 3d;
return (lookup);
}
....
sub vcl_fetch {
set beresp.grace = 4d;
set beresp.saintmode = 50s;
set beresp.ttl = 30s;
return (deliver);
}
#### CACHE REQUEST VARNISHLOG
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
11 SessionOpen c XXX.XXX.XXX.XXX 60750 XXX.XXX.XXX.XXX:2002
11 ReqStart c XXX.XXX.XXX.XXX 60750 479090107
11 RxRequest c GET
11 RxURL c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 RxProtocol c HTTP/1.0
11 RxHeader c Host: URL
11 RxHeader c X-Real-IP: XXX.XXX.XXX.XXX
11 RxHeader c X-Forwarded-For: XXX.XXX.XXX.XXX
11 RxHeader c Connection: close
11 RxHeader c User-Agent: GraphicalHttpClient 1.0.6 (Macintosh; Mac OS X 10.6.8; en_NL)
11 VCL_call c recv lookup
11 VCL_call c hash
11 Hash c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 Hash c URL
11 VCL_return c hash
11 Hit c 479090015
11 VCL_call c hit deliver
11 VCL_call c deliver deliver
11 TxProtocol c HTTP/1.1
11 TxStatus c 200
11 TxResponse c OK
11 TxHeader c Server: nginx/1.0.11
11 TxHeader c Content-Type: image/jpeg
11 TxHeader c Content-Transfer-Encoding: binary
11 TxHeader c Cache-Control: must-revalidate
11 TxHeader c Content-Length: 125395
11 TxHeader c Accept-Ranges: bytes
11 TxHeader c Date: Tue, 07 Feb 2012 14:23:00 GMT
11 TxHeader c X-Varnish: 479090107 479090015
11 TxHeader c Age: 5693
11 TxHeader c Via: 1.1 varnish
11 TxHeader c Connection: close
11 Length c 125395
11 ReqEnd c 479090107 1328624580.355833769 1328624580.357449532 0.000084162 0.000103474 0.001512289
11 SessionClose c Connection: close
11 StatSess c XXX.XXX.XXX.XXX 60750 0 1 1 0 0 0 29
#### CACHE REQUEST EXPIRED VARNISHLOG
12 BackendOpen b live XXX.XXX.XXX.XXX 41945 XXX.XXX.XXX.XXX 80
12 TxRequest b GET
12 TxURL b /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
12 TxProtocol b HTTP/1.1
12 TxHeader b Host: URL
12 TxHeader b X-Real-IP: XXX.XXX.XXX.XXX
12 TxHeader b X-Forwarded-For: XXX.XXX.XXX.XXX
12 TxHeader b User-Agent: GraphicalHttpClient 1.0.6 (Macintosh; Mac OS X 10.6.8; en_NL)
12 TxHeader b X-Varnish: 479090118
12 TxHeader b Accept-Encoding: gzip
12 RxProtocol b HTTP/1.1
12 RxStatus b 200
12 RxResponse b OK
12 RxHeader b Server: nginx/1.0.11
12 RxHeader b Date: Tue, 07 Feb 2012 14:26:00 GMT
12 RxHeader b Content-Type: image/jpeg
12 RxHeader b Connection: keep-alive
12 RxHeader b Content-Transfer-Encoding: binary
12 RxHeader b Cache-Control: must-revalidate
12 RxHeader b Content-Length: 125395
12 Fetch_Body b 4(length) cls 0 mklen 1
12 Length b 125395
12 BackendReuse b live
11 SessionOpen c XXX.XXX.XXX.XXX 50429 XXX.XXX.XXX.XXX:2002
11 ReqStart c XXX.XXX.XXX.XXX 50429 479090118
11 RxRequest c GET
11 RxURL c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 RxProtocol c HTTP/1.0
11 RxHeader c Host: URL
11 RxHeader c X-Real-IP: XXX.XXX.XXX.XXX
11 RxHeader c X-Forwarded-For: XXX.XXX.XXX.XXX
11 RxHeader c Connection: close
11 RxHeader c User-Agent: GraphicalHttpClient 1.0.6 (Macintosh; Mac OS X 10.6.8; en_NL)
11 VCL_call c recv lookup
11 VCL_call c hash
11 Hash c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 Hash c URL
11 VCL_return c hash
11 VCL_call c miss fetch
11 Backend c 12 live live
11 TTL c 479090118 RFC 120 -1 -1 1328624761 0 1328624760 0 0
11 VCL_call c fetch
11 TTL c 479090118 VCL 33 -1 -1 1328624758 -3
11 TTL c 479090118 VCL 33 40 -1 1328624758 -3
11 VCL_return c deliver
11 ObjProtocol c HTTP/1.1
11 ObjResponse c OK
11 ObjHeader c Server: nginx/1.0.11
11 ObjHeader c Date: Tue, 07 Feb 2012 14:26:00 GMT
11 ObjHeader c Content-Type: image/jpeg
11 ObjHeader c Content-Transfer-Encoding: binary
11 ObjHeader c Cache-Control: must-revalidate
11 VCL_call c deliver deliver
11 TxProtocol c HTTP/1.1
11 TxStatus c 200
11 TxResponse c OK
11 TxHeader c Server: nginx/1.0.11
11 TxHeader c Content-Type: image/jpeg
11 TxHeader c Content-Transfer-Encoding: binary
11 TxHeader c Cache-Control: must-revalidate
11 TxHeader c Content-Length: 125395
11 TxHeader c Accept-Ranges: bytes
11 TxHeader c Date: Tue, 07 Feb 2012 14:26:00 GMT
11 TxHeader c X-Varnish: 479090118
11 TxHeader c Age: 0
11 TxHeader c Via: 1.1 varnish
11 TxHeader c Connection: close
11 Length c 125395
11 ReqEnd c 479090118 1328624757.532856941 1328624760.899299860 0.000095606 3.364968061 0.001474857
11 SessionClose c Connection: close
11 StatSess c XXX.XXX.XXX.XXX 50429 3 1 1 0 0 1 284 125395
0 Debug - "lurker: 0x7f244cfd1e00 30 0"
This is an interesting question.
From DOC
When several clients are requesting the same page Varnish will send
one request to the backend and place the others on hold while fetching
one copy from the back end.
So, at any point in time there will be one client blocked even if you had enabled grace. Grace informs Varnish that you can serve all other n-1 clients with stale content until the first guy comes back with some content to refresh. There is no way to unblock that one guy [technically asynchronous fetch is not possible as such]
Check out this nice article I think what you are actually asking for is a planned feature for next release I hope

Resources