I'm using varnish to cache the content of my websites. It is working as it supposed, but there is a problem. Randomly it returns an 503 error, it is really strange, since the app servers are ok and the load is under .8, also the database server its ok. Here is part of my configuration:<div>
<br></div><div><div>backend app05 {</div><div> .host = "<a href="http://app05.site.com">app05.site.com</a>";</div><div> .port = "80";</div><div> .connect_timeout = 0.7s;</div><div> .first_byte_timeout = 30s;</div>
<div> .between_bytes_timeout = 30s;</div><div> .probe = {</div><div> .url = "/";</div><div> .interval = 5s;</div><div> .timeout = 1s;</div><div> .window = 5;</div><div> .threshold = 3;</div><div>
}</div><div>}</div><div><br></div><div>director app_director round-robin {</div><div> { .backend = app01; }</div><div> { .backend = app02; }</div><div> { .backend = app03; }</div><div> { .backend = app04; }</div><div>
{ .backend = app05; } </div><div>}</div><div><br></div><div>sub vcl_fetch {</div><div><br></div><div> # remove all cookies</div><div> # unset beresp.http.set-cookie;</div><div><br></div><div> # cache for 12 hours</div>
<div> # set beresp.ttl = 2h;</div><div><br></div><div> # Don't allow static files to set cookies.</div><div> if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|mp4|flv)(\?[a-z0-9]+)?$") {</div>
<div> unset beresp.http.set-cookie;</div><div> set beresp.ttl = 12h;</div><div> } else {</div><div> set beresp.ttl = 30m;</div><div> }</div><div><br></div><div> # If the backend server doesn't return properly, don't send another connection to it</div>
<div> # for 60s and try another backend via restart.</div><div> #</div><div> # <a href="https://www.varnish-cache.org/docs/trunk/tutorial/handling_misbehaving_servers.html">https://www.varnish-cache.org/docs/trunk/tutorial/handling_misbehaving_servers.html</a></div>
<div> # --</div><div> if(beresp.status == 500 || beresp.status == 503) {</div><div> set beresp.saintmode = 5m;</div><div> if (req.request != "POST") {</div><div><b> return(restart); # Here is the configuration to restart the connection if a server returns a 503 error, but it is not working</b></div>
<div> } else {</div><div> error 500 "Failed";</div><div> }</div><div> }</div><div><br></div><div> # Allow items to be stale if needed.</div><div> set beresp.grace = 1h;</div><div><br></div><div>}</div>
</div>