Fixing Varnish’s 503 Error

I have been trying to speed up somewhereinblog.com. Among many other things, I am trying to add Varnish cache. While setting Varnish on our test server, I have been facing 503 error. Basically this means that backend not responding correctly or taking more time.

This is what I got from varnishlog -c -m TxStatus:503

varnishlog -c -m TxStatus:503
...
3 VCL_call     c miss fetch
3 Backend      c 12 default default
3 FetchError   c http format error
3 VCL_call     c error deliver
3 VCL_call     c deliver deliver
3 TxProtocol   c HTTP/1.1
3 TxStatus     c 503

After many trail and error, I finally figure out the problem. Here is the solution worked for me.

First I tried to add .first_byte_timeout, .connect_timeout & .between_bytes_timeout in /etc/varnish/default.vcl because I know backend takes 1-2 secs to load.

backend default {
	.host = "127.0.0.1";  # IP address of your backend (Apache, nginx, etc.)
	.port = "8080";       # Port your backend is listening on
	.connect_timeout = 10s;
	.first_byte_timeout = 20s;
	.between_bytes_timeout = 10s;
}

Still the problem was not solved. Then I tried to add http_max_hdr. Default value http_max_hdr is 64. I increased it to 4 folds and added to /etc/default/varnish

DAEMON_OPTS="-a :80 \
    -T localhost:6082 \
    -f /etc/varnish/default.vcl \
    -u www-data -g www-data \
    -S /etc/varnish/secret \
    -p http_max_hdr=256 \
    -s malloc,2G"

After that 503 went away :D.

About Zakir Hyder

This entry was written by .

12. May 2014 by Zakir Hyder
Categories: Caching, Varnish | Tags: , , , , , , | Comments

Comments

  1. […] can reduce Varnish 503 errors. Varnish poll by opening a new TCP connection to the backend on which we send a preconfigured […]