(random) 503 errors with varnish

If you’re getting 503 errors when using varnish and everything works fine without varnish, then you may run in to the max-header-lines limit.

When looking at the output of varnishlog you might see errors like this when fetching the page from the backend:

FetchError   c http first read error: -2 0 (No error recorded)

I’ve noticed that certain web software sometimes goes berserk with adding cookies (usually the same ones over and over again, so you don’t see them in your browser).  But perhaps you really need that many headers. 🙂

Anyway, varnish has a default limit on the header-lines of 64. Increasing that size may help eliminate those pesky 503’s. The run-time parameter in varnish is http_max_hdr. You must set it on the command line when starting varnish. You cannot set this parameter in a .vcl file.

The syntax to set this run-time parameter to, say 256, is:

-p http_max_hdr=256

You usually add this the the start-up settings for varnish. On debian for instance, you add them to the DAEMON_OPTS in /etc/default/varnish.


This is what the varnish manual has to say about the http_max_hdr parameter:

  • Units: header lines
  • Default: 64

Maximum number of HTTP headers we will deal with in client request or backend reponses. Note that the first line occupies five header fields. This paramter does not influence storage consumption, objects allocate exact space for the headers they store.

Posted on May 21, 2012 at 20:06 by alex · Permalink
In: linux

Leave a Reply