Using varnish on a virtual server to accelerate your website

2016-10-04

Put Varnish on the Front Lines

Peter Cruz

Most clients hosting their own websites use the standard Apache web server to handle serving of their website’s pages, images and PHP based apps, such as WordPress. While that works great for small websites, there is, unfortunately, a hidden truth about Apache: it just can’t take it.

Apache, even though it is the most used web server in the world, is not designed to be efficient. Once it starts receiving a large load of traffic (and nowadays, that can happen easily), Apache will start disappointing you. The memory usage goes sky high. Your server runs out of RAM. CPU usage goes through the roof. Your website crashes.Fortunately, there's an amazing piece of open source software (read: free) that is designed to “shield” your website from dying a painful death under high load. This software is called Varnish. What Varnish does is it takes its place between your source server (the server with Apache and your website) and your website’s visitors. By doing this, it becomes the front line for hits to your website.

What happens is, basically, you point your website’s domain to the server running Varnish, not your source web server. Varnish takes care of pulling the content from your source server and then serves it to your audience. But it does a little bit of magic in that simple step: it also copies your website’s content into memory and from that moment on, it will continue serving it without bothering your source server.

This technique is simply known as web caching. Let’s review a very common scenario our clients use at Serverpoint.com, especially with our ColossusCloud product.

Let’s say you have a WordPress-based website, and it is hosted in a virtual private server using our VPS hosting platform, ColossusCloud. That virtual server also houses your MySQL database for Wordpress, and houses all of your blog posts and images. This virtual server is called the source server.

Now, you deploy another virtual server with Varnish in it. And with a few simple lines of configuration, you configure Varnish to pull content for your website from the source server. After that, you configure your domain’s DNS to point to the IP number of the Varnish server, not the source server. And magically, as Varnish gets hits to your website, it will get the content from the source server, cache it and serve it to your visitors.Why do this? Varnish is extremely efficient at serving content. It can easily handle millions of hits per minute with a low level of computational and RAM resources, unlike Apache, which would crash under much less load. It also hides the IP of your real source server from the Internet, as only Varnish would know that. To sum it all up: Varnish is a very powerful piece of software that can efficiently handle very complex levels of caching.

We’ve been using Varnish for quite some time here, at ServerPoint. Contact our expert team today and we'll happily help you deploy Varnish!Visit http://www.varnish-cache.org for more information on Varnish.