How to test Varnish using cURL

This article will show you how to test Varnish by analyzing the HTTP headers you receive from the cURL command. There are a multitude of other ways to test this, but I find using cURL to be the easiest.

DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
RELATED PRODUCTS Linux-based VPS or dedicated servers

Testing varnish is crucial to ensure your websites are being cached and served in a timely matter, here is a quick test to ensure Varnish is working.

First, log in to any server that has cURL installed, if it is not installed you can easily install it running:

Ubuntu -

apt-get install curl

CentOS -

yum install curl

Once cURL is installed, you can then test Varnish by analyzing the headers, we will use the capital I flag to retrieve only the headers.

curl -I

Replacing with a domain that is hosted on your server, or if you are testing from the default document root - use your server IP. You should see a similar output depending on your configuration.

HTTP/1.1 200 OK
Date: Tue, 18 Nov 2014 19:05:29 GMT
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
Content-Type: text/html;charset=UTF-8
X-Varnish: 16
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive

Two key flags that you want to pay attention to that let you know Varnish is indeed working correctly:

X-Varnish: 16
Via: 1.1 varnish-v4

That is it, you have verified the functionality of Varnish on your server.

Hjalp denne artikel?
Tak for din feedback.
Det glæder os, at vi kunne hjælpe! Er der andet, vi kan gøre for dig?
Beklager. Er der andet, vi kan gøre for at hjælpe dig?