• 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.

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

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Advanced Tweaks and Optimization for Varnish Cache

    Varnish Cache usually works the best out of the box. However, minimum tweaks and optimization can make Varnish to work better with WordPress.

  • Setup Varnish Cache with Apache and TLS/SSL Termination

    Varnish demands experience and keeping an eye on your server. For that reason, test this guide on a non-production, non-money-making site with SSL. It will cost $5/month or less to host such a WordPress site on a VPS. If you manage the HTTPS site with Varnish for a couple of months, you’ll gain some confidence. […]

  • Configure Varnish Cache (HTTPS, Ubuntu 14.04, HP Cloud)

    Here is how to configure Varnish Cache for a HTTPS website, running on Ubuntu 14.04 on HP Cloud. Use a dev server to get used with Varnish.

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 (24.3K 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

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

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

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