Configuring Varnish Cache to Run With Vesta Control Panel
#howto ,#tutorial #VPS – Configuring Varnish Cache to Run With Vesta Control Panel – This tutorial explains step by step guide (with pics) about Configuring Varnish Cache to Run With Vesta Control Panel
A guide with screenshot pics on how to setup Varnish Cache server and get it running together with full Vesta CP which by default comes with LAMP and Nginx as frontend proxy. This article is a follow up of my previous article and here I come with it as promised. I tagged this article as advanced because you have to firstly read previous tutorials on how to install VestaCP and Varnish Cache.
Before we start, you may wondering does we have to really do this? Is installing Varnish on Vesta really necessary? Well, the answer depends whether you really need it or not. Some people say that installing Varnish in front of Nginx is not quite necessary because Nginx itself is pretty good handling static web files. My personal opinion, if you use Varnish setup to store caches in Disk (even it is SSD) then you better ditch it. Varnish with Nginx will be great only if you use RAM-based caching because theoretically it is slightly faster than having to pass the process to disk.
So, here’s what you gonna need:
- A SSH client like Putty and basic knowledge about how to use it.
- Basic knowledge about common Unix command to SSH to your server.
- A server or VPS with at least 512MB of RAM (1GB recommended). If you not already have one then you can read my list of recommended VPS providers or this top low end cloud server providers. Quick recommendation: Atlantic.net, Digital Ocean and RamNode.
- Make sure your server is running one of VestaCP’s supported OS: RHEL 5/6, CentOS 5/6, Debian 7 or Ubuntu 12.04/12.10/13.04/13.10/14.04. Using minimal template is recommended.
- About 20 minutes of your time
- a cup of coffee or tea.
Stage 1 – Installing VestaCP
Before we continue, I should tell you that the tutorial below done in a VPS with 512MB RAM running CentOS 6.6 32-bit. It is recommended to use higher RAM. You have to adjust the command if your server is running other than CentOS.
Step 1 – Login to your server as root
Step 2 – Install Vesta CP using command below:
curl -O http://vestacp.com/pub/vst-install.sh bash vst-install.sh
Step 3 – It will then ask you with series of questions. Just answer it accordingly:
Step 4 – Once done you’ll see something like this which you can see your login URL along with admin username and some random password (you can change that later).
More explanation and screenshots:
- How to install VestaCP on CentOS VPS
Stage 2 – VestaCP Basic Configuration
Some tasks you have to firstly proceed are:
- Changing default admin password
- Adjust hosting package configuration
- Add new website on it (DNS entries will be generated automatically via this task)
- Add new database on it (if your website need it)
- Uploading / migrating your website on it
I don’t explain it again because it is explanatory or you can simply refer to my previous guides:
- Basic VestaCP setup and how to add new website
- How to install WordPress on VestaCP
Configuration I use for the purpose of this tutorial:
- VestaCP user: admin
- Domain: servermomtest.org (doesn’t exist, test purpose only)
- Package: Default (httpd, nginx and named – all default)
- App: WordPress installed.
- Web directory: /home/admin/web/servermomtest.org/public_html
Stage 3 – Installing Varnish Cache
In this article I use Varnish Cache v3.x simply because some syntax on its configuration file has been changed in version 4.x – which I don’t quite familiar yet. However feel free to use version 4.x if you wish and I wrote a tutorial about it as well:
- How to Install Varnish Cache 4 on CentOS 7
Steps below are the short version of my previous guide to install Varnish Cache 3 on CentOS:
Step 1 – Go to Varnish website to see stable version available at
In my situation the current stable release is Varnish Cache 4.0.3 while its v3 is Varnish Cache 3.0.7. Click on the Instructions link to see where you can get its package.
Step 2 – Add Varnish repository for the version you want. Command below will add Varnish 3.0.7:
rpm -Uvh https://repo.varnish-cache.org/redhat/varnish-3.0.el5.rpm
Step 3 – Now you can install Varnish using yum:
yum install varnish -y
Done. Varnish is now installed (but not running yet)
Stage 4 – Varnish Configuration
Step 1 – We have to setup Varnish so it will run on port 80. The scenario will be like this: Varnish listen on port 80, Nginx on port 8082, then Apache on port 8080.
Web request = Varnish (80) -> Nginx (8082) -> Apache (8080)
Now use your favorite text editor to edit Varnish configuration. For me Nano will come in handy:
The file contains 4 alternative configurations and only 1 is active which is the one with no comment mark (#) which in my situation it is Alternative 3.
Step 2 – Change few important lines started with VARNISH_LISTEN_PORT. Change it to 80
Step 3 – Scroll down the page then find and change VARNISH_STORAGE_SIZE to reasonable amount of RAM you want to allocate it as storage for the cache files made by Varnish. As my VPS has only 512MB of RAM so I will allocate 256MB of it.
Step 4 – Also change
so it will look like this:
Now save changes and exit text editor. In Nano it is Control+O then Control+X.
Step 5 – Next, configure Varnish default VCL file located in /etc/varnish/. That VCL file holds configuration to tell varnish where to look for the webserver content:
Here what you gonna do:
- change .host ip from 127.0.0.1 to your server public IP
- change .port 80 to .port 8082 which where nginx should listening.
- uncomment (remove the # symbol) at sub vcl_recv section
- add one } symbol at the end of that section
make sure it looks similar to this
Save changes and exit the editor (Control+O then Control+X)
That’s it for now. Coming up in the Part 2 of this tutorial: Stage 5 and Stage 6 (Vesta CP configuration).
Next: VestaCP Nginx Configuration for Varnish (Part 2: Stage 5 and so on)
This post Configuring Varnish Cache to Run With Vesta Control Panel is part of ServerMom.