October 26, 2021
4 min read time

Two-Minute Tech Tuesdays - Varnish on Google Cloud Platform


In this week’s Two Minute Tech Tuesday, we're going to revisit the cloud. We've already done three episodes about running Varnish in the cloud, covering general concepts and how to run Varnish on AWS and Azure infrastructure. This week's episode is about Google Cloud Platform, or GCP.


  1. Our story starts on the GCP dashboard, and more specifically on the VM Instances overview. We already have a web server and we would like to cache that web server using Varnish, so click Create Instance to create a new Varnish instance.

  2. Instead of going for a new VM instance from scratch, click Marketplace and type Varnish to get the Varnish instance, there’s multiple images to choose from but we’re using an Ubuntu image in this example.

  3. Name it Varnish, and stick with the default values in terms of zone, hardware machine type, boot disk, storage and networking. The networking settings, and more specifically the firewall settings, have been prepared in advance and are part of the default image.

  4. Next, it's just a matter of accepting the terms and conditions and deploying the machine. 

  5. Once the deployment and provisioning of the server is finished, go back to the Overview page to see your freshly created Varnish instance. Copy the public IP address, open up a new browser window, and paste it to see the landing page.

  6. Click the Next Steps button to see a detailed Configuration Guide. We can skip the Configuration Guide for now, because we know exactly what we want to do: access the server via SSH.

  7. To access it, we need the IP address. Use SSH command; you can use a pre-configured SSH key pair for credentials, which you can configure on the Metadata page under Settings.

  8. Once you’re in, open the default VCL file located in etc/varnish/default.vcl.

  9. Remove the placeholder line that displays the welcome page, modify the backend using the IP address of the web server and connect on Port 80.

  10. Close the editor and run sudo systemctl edit varnish to edit the Varnish runtime parameters.

  11. Change the size of the cache from 256MB to 2GB, then save and close that file and run sudo systemctl restart varnish to restart the Varnish service.

  12. You can then go back to your browser and refresh, and the welcome page will be replaced with the actual cached content coming from the web server.

And that’s it. You've just set up the Varnish server using the official machine image on Google Cloud Platform. See you next week for more content, and another Two Minute Tech Tuesday.