• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Get Started with Varnish Cache

By Abhishek Ghosh May 2, 2014 7:19 pm Updated on May 2, 2014

Get Started with Varnish Cache

Advertisement

With Cloud Servers, it is easier to spin up a separate server to work as front end. Let us get started with Varnish Cache setup with commands. We talked about Varnish Cache before, we said that; Varnish is a web accelerator for dynamic web pages with lots of content like WordPress. Unlike other client-side proxies or servers (read what is reverse proxy), Varnish was designed from the ground up as a Web accelerator. Varnish works by handling requests before they goes to your backend, whether your backend is Apache2, Nginx – does not matter. If only it has no request cached, it will forward the request to the backend and then cache its output.

 

Get Started with Varnish Cache : Spin a Server

 

We are using Ubuntu 14.04 LTS, 512 MB server will work fine for the most. First update the current packages and install Varnish :

 

Vim
1
2
apt-get update && apt-get upgrade
apt-get install varnish

Edit the daemon options for Varnish to instruct it to load custom configuration:

Advertisement

---

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
nano /etc/default/varnish
# output; scroll down and you'll get
 
## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request.  Use a 1GB
# fixed-size cache file.
#
DAEMON_OPTS="-a :6081
             -T localhost:6082
             -f /etc/varnish/default.vcl
             -S /etc/varnish/secret
             -s malloc,256m"
 
# change
# -f /etc/varnish/default.vcl  to
# -f /etc/varnish/user.vcl

Get Started with Varnish Cache

From the configuration above, we need edit the value -s malloc,256m :

Vim
1
2
-s malloc,360m
# for 512mb server, approximately we should allow some RAM left!

Copy default.vcl to your own file :

Vim
1
2
3
cd /etc/varnish && cp default.vcl user.vcl
nano user.vcl
# the file will open

 

Get Started with Varnish Cache : Set up Backend

 

This is default :

Vim
1
2
3
4
backend default {
    .host = "127.0.0.1";
    .port = "80";
}

It is actually caching Apache which is currently on port 80 on the same server, so change accordingly the IP. You should restart Varnish :

Vim
1
service varnish restart

Varnish runs on port 6081, we will edit the file :

Vim
1
2
3
4
sub vcl_fetch
{
    set beresp.ttl = 2h;
}

# We should change Apache’s port, edit /etc/apache2/ports.conf :
nano /etc/apache2/ports.conf

Find NameVirtualHost *:80 and Listen 80 and change 80 in each to another port. We will change to 8080:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
NameVirtualHost *:8080
Listen 8080
# NameVirtualHost will not be required in later versions
 
# edit /etc/apache2/sites-available/000-default.conf and set virtual host to listen at :
# <VirtualHost *:8080>
# configure Varnish to start on port 80 :
nano /etc/default/varnish
# should look like this
DAEMON_OPTS="-a :80
# Open /etc/varnish/user :
 
nano /etc/varnish/user
# should look like this :
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}
# change host! that is for single server setup
# restart services
service apache2 reload
service varnish restart

This is the basic setup with Varnish. It itself will give you a good polish. Get used with Varnish and tweak the performance. We could install on same server, but actually its better to use a separate server. It makes the load balance management easier.

This Article Has Been Shared 373 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Get Started with Varnish Cache

  • Free Cloud Storage From Unbuntu One Plus Desktop app for Windows 7

    Free Cloud Storage From Unbuntu One provides 5 GB of Public Cloud Space. Ubuntu One now offers client apps for Windows 7, Linux, iPhone, Android devices.

  • Cloud Load Balancer – Mechanism and Types of Load Balancer

    Cloud Load Balancer is Cloud Computing based system to distribute the load on one server, it can be based on various technologies and complicated levels.

  • In-memory Technology : The Mastery of Big Data

    In-memory technology has the potential to initiate a new computing era. The mastery of Big Data gives the promise of the Real-Time Enterprise to reality.

  • Free Bootstrap CMS : PHP, MySQL Powered With Twitter Bootstrap Design

    Free Bootstrap CMS is a complete CMS powered by PHP, MySQL and comes with customizable Twitter Bootstrap Design. Let us see how it looks and how to install. Free Bootstrap CMS is available on Github as Free Software.   Free Bootstrap CMS : Origin and Source Code     e107 is a free (open-source) content […]

  • Adding Schema.org Structured Data in Genesis Theme

    Adding Schema.org Structured Data in Genesis Theme without using any plugin is quite easy as Genesis has great documentation and has excellent existing markups.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (22.1K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Samsung Galaxy S22 Ultra: Long Term Review June 30, 2022
  • How to Make the Most of Your S Pen (S22 Ultra) June 29, 2022
  • Safe Chargers for Samsung Galaxy S22 Ultra June 27, 2022
  • How Telecoms Can Use The Cloud To Power Their 5G Network June 24, 2022
  • A Beginner Guide to Cloud Computing for Development June 22, 2022

About This Article

Cite this article as: Abhishek Ghosh, "Get Started with Varnish Cache," in The Customize Windows, May 2, 2014, July 1, 2022, https://thecustomizewindows.com/2014/05/get-started-varnish-cache/.

Source:The Customize Windows, JiMA.in

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Privacy Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2022 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy