Starting Varnish

This tutorial will assume that you are running Varnish on a Linux system.

Check out our install guide to learn how to install Varnish on the various platforms.

When properly installed you start Varnish with sudo systemctl start varnish. This will start Varnish if it isn’t already running.

Now you have Varnish running. Let us make sure that it works properly: use your browser to go to http://127.0.0.1/

The default configuration will try to forward requests to a web application running on the same machine as Varnish was installed on. Varnish expects the web application to be exposed over http on port 8080.

If there is no web application being served up on that location Varnish will issue an error. Varnish is very conservative about telling the world what is wrong so whenever something is amiss it will issue the same generic Error 503 Service Unavailable.

You might have a web application running on some other port or some other machine. Let’s edit the configuration and make it point to something that actually works.

Fire up your favorite editor and edit /etc/varnish/default.vcl. Most of it is commented out but there is some text that is not. It will probably look like this:

vcl 4.1;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

You can change the .host and .port properties to match the host and port of your origin server:

vcl 4.1;

backend default {
    .host = "example.com";
    .port = "80";
}

Now issue sudo systemctl varnish reload to make Varnish reload its configuration. Internally, this will reload the VCL configuration without restarting the varnishd process.

When you navigate to http://127.0.0.1 (or the hostname or IP address of your server), you will see the content of your origin web server.