• 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 » Advanced Tweaks and Optimization for Varnish Cache

By Abhishek Ghosh May 5, 2014 5:12 am Updated on May 5, 2014

Advanced Tweaks and Optimization for Varnish Cache

Advertisement

Varnish Cache usually works the best out of the box. However, minimum tweaks and optimization can make Varnish to work better with WordPress. When we are talking bout WordPress, obviously W3 Total Cache configuration comes in to question – because W3 Total Cache has separate option for configuring W3 Total Cache for Varnish. So, how should we pass the page requests to get the maximum out from Varnish Cache? Read Get Started with Varnish Cache for setting up of Varnish Cache in case you have not installed Varnish Cache yet. We are writing the things divided in to two sub headers – general tweaks and specific for WordPress with W3 Total Cache configuration.

 

Advanced Tweaks and Optimization for Varnish Cache

 

So, actually we are serving content via Varnish Cache – not Apache2 and PHP handlers directly. In the previous guide we changed the port of Varnish to 8080, if we kept it to default; if your server’s IP was 125.23.24.987, if you point towards :

Vim
1
http://125.23.24.987:6081

You should be able to view a copy of the webpage. In fact, you can keep it to default and make Apache2 to Listen at port 80 and Port 8080. Virtual Host, in that case should handle port 8080 only. This works great for adding load balancer – read Load Balancer Service from Rackspace Guide. Load balancer should Listen with http:80 method, use Round Robin Algorithm and as node; your server’s port 6081 should serve the content to load balancer. As load balancer has a different IP and we can control access precisely, by no way any request will go directly to Apache2 and PHP handlers directly. You domain example.com is fully cached. But, for WordPress we need to keep the Admin area cache free :

Advertisement

---

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
nano /etc/varnish/user.vcl
# Edit the file like below
sub vcl_recv
{
    if (req.http.host ~ "example.com" ||
        req.url ~ "^/admin")
    {
        return (pass);
    }
}
# restart, varnish should be reloaded first
service varnish restart
service apache2 reload

You might face Guru Meditation Error with improper setup.

This editing will work great for the most :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
backend default {
    .host = "127.0.0.1";  # backend
    .port = "8080";       # Port of backend
    .probe = {
        .url = "/";
        .timeout = 34ms;
        .interval = 1s;
        .window = 10;
        .threshold = 8;
    }
}
 
sub vcl_recv
{
   # for WordPress the admin area
   if (req.http.host ~ "example.com" ||
        req.url ~ "^/admin" ||
        req.http.Cookie ~ "logged_in" ||
        req.request == "POST")
    {
        return (pass);
    }
 
    # Set / unset cookies
    unset req.http.Cookie;
 
    # Set Grace Time to one hour
    set req.grace = 1h;
}
 
sub vcl_fetch
{
    # Set the TTL for cache object
    set beresp.ttl = 5m;
 
    # Set Grace Time
    set beresp.grace = 1h;
}

You can read the docs :

Vim
1
https://www.varnish-cache.org/docs/2.1/index.html

 

Advanced Tweaks and Optimization for Varnish Cache : For WordPress

 

It actually does not matter whether you are configuring W3 Total Cache with Varnish or not as long you are serving content via a load balancer – W3 Total Cache can not give much higher performance with our setup.

Advanced Tweaks and Optimization for Varnish Cache

Yet, if you want to add the servers, add main server’s IP where Varnish is running. For multiple server, the configuration would be more complicated if you involve W3 Total Cache :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# taken from highscalability.com
# written by Jeff
 
backend server1 {
  .host = "10.0.0.10";
}
backend server2{
  .host = "10.0.0.11";
}
director multi_servers1 round-robin {
  {
    .backend = server1;
  }
  {
    .backend = server2;
  }
}
director multi_servers2 random {
  {
    .backend = server1;
  }
  {
    .backend = server2;
  }
}

There is enough change that, W3TC or any PHP script would not follow the logic and ultimately you’ll end up serving 503 pages. You can end up complicating the simple setup :

Vim
1
http://wordpress.org/support/topic/plugin-w3-total-cache-varnish-cache-not-purged-sends-get-requests-instead-of-purge

For our way of guide with Rackspace Cloud Server and Loadbalancer, we need not to involve Varnish Cache.

Tagged With advanced wordpress optimization , varnish optimizing
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 Advanced Tweaks and Optimization for Varnish Cache

  • Get Started with Varnish Cache

    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.

  • WordPress & PHP : Different AdSense Units on Mobile Devices

    Here is How To Serve Different AdSense Units on Mobile Devices on WordPress With PHP. WordPress Has Function Which Can Be Used In Free Way.

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

  • Varnish Cache : The HTTP Accelerator

    Varnish is a web accelerator for dynamic web pages with lots of content like WordPress. Unlike other client-side proxies or servers ( read about reverse proxy), Varnish was designed from the ground up as a Web accelerator. Varnish is used by Facebook, Twitter, E-Bay and lot of websites. Actually we published about Varnish HTTP Accelerator […]

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

  • Market Segmentation in BriefSeptember 20, 2023
  • What is Booting?September 18, 2023
  • What is ncurses?September 16, 2023
  • What is JTAG in Electronics?September 15, 2023
  • iPhone 15 Pro Max Vs Samsung Galaxy S22/S23 UltraSeptember 14, 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