<div dir="ltr">Have you changed the default grace (10s)?</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div>Guillaume Quintard<br></div></div></div>
<br><div class="gmail_quote">On Sun, Sep 17, 2017 at 8:36 PM, Vassilis Aretakis <span dir="ltr"><<a href="mailto:vassilis@onlab.xyz" target="_blank">vassilis@onlab.xyz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have a setup which was working on Varnish 3.0 but not with 4.1<br>
<br>
The stale pages where servered in case the backends where sick. But I cannot make this work with varnish 4.<br>
Can you help me to make it serve the cached pages in case backends are gone?<br>
also session-cookies can be removed/ignored<br>
<br>
My config is:<br>
<br>
<br>
vcl 4.0;<br>
import directors;<br>
import std;<br>
<br>
backend b1 {<br>
.host =<br>
.port = "80";<br>
.first_byte_timeout = 180s;<br>
.between_bytes_timeout = 120s;<br>
.probe = {<br>
.url = "/healthy_check/d.php";<br>
.interval = 10s;<br>
.timeout = 2 s;<br>
.window = 7;<br>
.threshold = 1;<br>
}<br>
}<br>
<br>
<br>
backend b2 {<br>
.host =<br>
.port = "80";<br>
.first_byte_timeout = 180s;<br>
.between_bytes_timeout = 120s;<br>
.probe = {<br>
.url = "/healthy_check/d.php";<br>
.interval = 10s;<br>
.timeout = 2 s;<br>
.window = 7;<br>
.threshold = 1;<br>
}<br>
}<br>
<br>
<br>
sub vcl_init {<br>
new vdir = directors.round_robin();<br>
vdir.add_backend(b1);<br>
vdir.add_backend(b2);<br>
}<br>
<br>
sub vcl_recv {<br>
<br>
set req.backend_hint = vdir.backend();<br>
<br>
#Ignore adminpanel<br>
if (req.url == "^/adminpanel/.*" ||<br>
req.url == "^/adminApplication/.*" ||<br>
req.url ~ "^/adminApplication/" ||<br>
req.url ~ "^/adminpanel/" ||<br>
req.url ~ "^/newsfeed.php" ||<br>
req.url ~ "^/comment") {<br>
return (pass); # unset req.http.Cookie;<br>
}<br>
<br>
if (req.method != "GET" &&<br>
req.method != "HEAD" &&<br>
req.method != "PUT" &&<br>
req.method != "POST" &&<br>
req.method != "TRACE" &&<br>
req.method != "OPTIONS" &&<br>
req.method != "DELETE") {<br>
/* Non-RFC2616 or CONNECT which is weird. */<br>
return (pipe);<br>
}<br>
if (req.method != "GET" && req.method != "HEAD") {<br>
/* We only deal with GET and HEAD by default */<br>
return (pass);<br>
}<br>
#set req.http.grace = "none";<br>
<br>
return (hash);<br>
}<br>
<br>
sub vcl_pipe {<br>
<br>
return (pipe);<br>
}<br>
<br>
sub vcl_pass {<br>
return (fetch);<br>
}<br>
<br>
sub vcl_hit {<br>
if (obj.ttl >= 0s) {<br>
# normal hit<br>
return (deliver);<br>
}<br>
# We have no fresh fish. Lets look at the stale ones.<br>
if (std.healthy(req.backend_hint)<wbr>) {<br>
# Backend is healthy. Limit age to 10s.<br>
if (obj.ttl + 10s > 0s) {<br>
set req.http.grace = "normal(limited)";<br>
return (deliver);<br>
} else {<br>
# No candidate for grace. Fetch a fresh object.<br>
return(fetch);<br>
}<br>
} else {<br>
# backend is sick - use full grace<br>
if (obj.ttl + obj.grace > 0s) {<br>
set req.http.grace = "full";<br>
return (deliver);<br>
} else {<br>
# no graced object.<br>
return (fetch);<br>
}<br>
}<br>
}<br>
<br>
sub vcl_miss {<br>
return (fetch);<br>
}<br>
<br>
sub vcl_backend_fetch {<br>
set bereq.backend = vdir.backend();<br>
}<br>
<br>
sub vcl_backend_response {<br>
# Happens after we have read the response headers from the backend.<br>
#<br>
# Here you clean the response headers, removing silly Set-Cookie headers<br>
# and other mistakes your backend does.<br>
unset beresp.http.set-cookie; set beresp.grace = 1h;<br>
if (beresp.status > 500) {<br>
return (retry);<br>
}<br>
if (bereq.url == "^/") {<br>
set beresp.ttl = 60s;<br>
}<br>
<br>
#jpeg caching (forced)<br>
if (bereq.url ~ "\.(png|gif|PNG|JPG|JPEG|jpg|j<wbr>peg|swf|css|js)$" ||<br>
bereq.url ~ "\.(png|gif|PNG|JPG|JPEG|jpg|j<wbr>peg)&width.*" ||<br>
bereq.url ~ "\.(png|gif|PNG|JPG|JPEG|jpg|j<wbr>peg)?.*") {<br>
set beresp.http.cache-control = "max-age = 2592000";<br>
}<br>
return (deliver);<br>
}<br>
<br>
sub vcl_hash {<br>
hash_data(req.url);<br>
if (req.http.host) {<br>
hash_data(req.http.host);<br>
} else {<br>
hash_data(server.ip);<br>
}<br>
return (lookup);<br>
}<br>
<br>
sub vcl_deliver {<br>
set resp.http.grace = req.http.grace;<br>
}<br>
______________________________<wbr>_________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" target="_blank">https://www.varnish-cache.org/<wbr>lists/mailman/listinfo/varnish<wbr>-misc</a></blockquote></div><br></div>