If you just created an instance for this first install the updates by typing this command:
sudo apt-get update sudo apt-get install varnish
After this you would need to configure varnish
Once you have both apache and varnish installed, you can start to configure them to ease the load on your server from future visitors. Varnish will serve the content on port 80, while fetching it from apache which will run on port 8080.
Let’s go ahead and start setting that up by opening the
sudo vi /etc/default/varnish
Uncomment all of the lines under “DAEMON_OPTS”—under Alternative 2, and make the configuration match the following code:
DAEMON_OPTS="-a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m"
After this you will need to configure default.vcl which can be found here:
Reboot the varnish server after that:
Save and exit the file and proceed to restart Apache and Varnish to make the changes effective.
Restart the apache on the server that you are including in the varnish as well as varnish.
sudo service apache restart sudo service varnish restart
Accessing your domain should instantly take you to the varnish cached version, and you can see the details of varnish’s workings with this command: