Is varnish error 503 frustrating you?
Usually, this error occurs mainly when the webserver becomes unavailable. This can be due to overload, server maintenance and so on.
At Bobcares, we often receive requests to fix this error as part of our Server Management Service.
Today, let’s get into this error in detail and see how our Support Engineers fix it easily.
How does Varnish error 503 show up?
As we all know, Varnish is an HTTP accelerator that improves web performance and reduces server load.
If you have a website that caches content with Varnish cache, then you might have come across Varnish cache server error 503: Service unavailable.
But, why does this happen?
This error indicates that the Varnish is not able to reach the back end server.
There are a few reasons like timeouts, overload, etc that causes this error.
Causes and fix for Varnish error 503
Though Varnish is tremendously fast, it often shows up tricky errors like 503.
Let’s now check the various causes of this error and see how our Support Engineers fix it.
1. Too many requests
Sometimes, the Varnish cache server makes too many requests to the back end server without getting a response. In such cases, instead of making an infinite number of requests to an unhealthy back end, Varnish cache issues the 503 error.
To fix the error, we initially check the logs for all the 503 errors by using varnishlog. So, we use the command,
$ varnishlog -q 'RespStatus == 503' -g request
On checking the logs, we mostly get a “FetchError no backend connection” error. In such cases, we then check whether the ports, HTTP service, original server, etc are operating correctly.
For instance, we will make sure that Apache listens to port 8080
2. Timeouts
Sometimes, Varnish cache serves 503 even if backend id responding. This is due to timeouts.
To avoid the errors due to timeout, we add appropriate values for .connect_timeout and .first_byte_timeout in the backend default VCL section. We choose this timeout value based on the application running in the webserver.
Similarly, disabling KeepAlive in order to drop the connections will also resolve the error.
3. Length of cache tags
Yet another reason for Varnish error 503 in Magento sites can be the insufficient length of the cache tags.
By default, Varnish supports a default cache length of 8192 bytes. When Magento cache tags exceed this value, it shows error in the browser.
The fix involves increasing the default value of the http_resp_hdr_len parameter in the Varnish configuration file. Further, we increase the default response size using the http_resp_size parameter too.
On CentOS7 server, we set the values in the file /etc/varnish/varnish.params. A sample set of options appear as:
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
-p thread_pool_min=${VARNISH_MIN_THREADS} \
-p thread_pool_max=${VARNISH_MAX_THREADS} \
-p http_resp_hdr_len=65536 \
-p http_resp_size=98304 \
Similarly in Ubuntu or Debian servers, we set the values in /etc/default/varnish file.
[Need more assistance to fix this error?- We’ll help you.]
Conclusion
In short, Varnish error 503 occurs mainly when the webserver becomes unavailable due to too many requests, insufficient timeout values, etc. Today, we have discussed this error in detail and saw how our Support Engineers fix it for our customers.
0 Comments