In this tutorial, we will cover how to install and configure Varnish with NGINX server to improve performance.
As explained on varnish-cache.org:
"Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture."
In this tutorial, we'll see how to setup a Varnish instance with default parameters. Remember to define and analyse the best setup for your goals (example: Magento).
For this tutorial, we assume you already installed and configured an Nginx Web-Engine on a Linux distribution which will run on port 80. You can setup a new web server or install Varnish on your actual server.
All communications between Varnish and your Nginx server will be done using the private network. In this configuration, we'll also assume that your have a Load Balancer which will manage the HTTPS connection. On our private network, all connections will be done through 80 for Varnish and 8081 for NGINX.
You'll also need root or sudo accesses to run the container.
Lastly, check of course that Docker is installed, which is the default setup for servers at Artifakt.
We want to have the Varnish instance available for users and which will discuss with the NGINX server as a backend instance.
Be sure you have all prerequisites checked to go further in this procedure.
Install Varnish as a Docker container
The easy way uses our own internal docker
docker run --name=varnish -p 80:80 --restart=always registry.artifakt.io/varnish:5
Injecting specific configuration
docker run --name=varnish --restart=always -p 80:80 \
-v $VCL_PATH:/etc/varnish/default.vcl registry.artifakt.io/varnish:5
docker rm -f varnish