If you have a Blog, e commerce or a corporate website you should not overlook the importance of page loading speed. In this post you will find out one of the most popular methods frequently used by high-traffic websites that will help to speed up your site and increase its high-load stress resistance.
Have you ever wondered about how the most visited websites, such as news sites or top internet shops, are able to remain so responsive while maintaining all those high-load traffic?
Off course they have high-load web cluster and DB figured out but, more than that, the most important feature they use is a web accelerator like Varnish (varnish-cache.org) which implies frontend caching using http reverse proxy to improve overall frontend performance and webpage download speed. Twitter, Facebook, Vimeo, Wikipedia, The New York Times are only some examples of well- known sites that use Varnish.
Either way, before going into the key argument of this post, have you ever asked yourself why it is so important to stress-resistant and fast-loading site? The answer might seem pretty easy but the reasons are probably not, here are some of most important arguments:
- Google proclaimed website’s speed of response as an important factor for search results ranking;
- The visitors are desperate, thereby the site speed is in accordance with the amount of conversions (highlighted the importance of this factor for e-commerce websites);
- Faster website is considered more “reliable” for users;
Thinking about the last versions of CMS like WordPress or Drupal or e commerce management systems like Magento or PrestaShop, the obvious fact is that they are not brilliant and pretty heavy requiring important resources from the server that is hosting them, while the biggest part of implementation work is probably dedicated to optimization of response speed.
Turning to the question how to apply Varnish to your website?
Moreover, web server (Apache, Ngix, IIS, etc.) should not be necessarily located on the same server – in many cases Varnish location is on its own server while web-server has another server location (which Varnish detects as “backend”).
In addition Varnish offers features of Load Balancer managing more backends. Varnish Configuration Language (VCL) provides enhanced flexibility with an opportunity to realize configurations and behavior on advanced levels.
Here is the solution for proper installation and configuration of Varnish software:
Beginning with software installation, in our case we access CentOs 7 server.
Step 1: Adding EPEL repository
Like before it’s necessary to add EPEL repository:
yum install epel-release
yum -y update
Step 2: Installing Varnish
At this point we install Varnish with a command:
yum -y install varnish
Step 3: Activating Varnish
We should configure Varnish while it’s automatic launch on server boot:
systemctl enable varnish
In this case we should provide manual launch:
systemctl start varnish
In order to verify Varnish activation we can run this command:
systemctl status varnish
This command provides info about installed version:
Now here is the way to configure Varnish:
Step 4: configuring Varnish input settings:
Varnish default configuration is set to respond port 6081, while web server is expected to respond to localhost on port 8080, so it’s necessary to configure webserver (Apache, Ngix, etc.) to respond the indicated port number. This way, while configuring Varnish reply to HTTP standard port, the following command needs to be set:
Modify line VARNISH_LISTEN_PORT=6081 in VARNISH_LISTEN_PORT=80
Restart Varnish with this command:
systemctl restart varnish
From this moment, Varnish will be elaborating all the requests recalling webserver intervening between the client and webserver accepting the navigation scheme as indicated before.
Step 5: Location of configuration file
Varnish file with default config is located in this directory:
Nevertheless these installation settings provide necessary minimum, Varnish is extremely flexible using powerful configuration language. Some simple search on Google will provide all necessary templates ready to use with most popular CMS.
Our professional staff will help you to configure Varnish according to your needs.