• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer
sharadchhetri.com

sharadchhetri.com

Linux,Cloud Computing And DevOps

  • Home
  • Linux
  • CloudComputing
    • Introduction Cloud Computing
    • Amazon AWS
  • Free E-Books
  • About Me

Setup varnish cache server for wordpress site

September 30, 2013 by Sharad Chhetri Leave a Comment

In this turorial we will learn,how to configure Varnish 3.x vcl file for WordPress.We will setup varnish cache server for wordpress site.This will increase the page load speed of the site/blog.
Recently I migrated my server to DigitalOcean.To migrate the server from web hosting to cloud server was not done first time,it was also done in past. Reason to migrate to DigitalOcean was its cheap price and good service.
The biggest reason is now I am going to write many things which actually comes under sharadchhetri.com network.
I configured the varnish in sharadchhetri.com and my blog is wordpress based. Now here I got a challenge after reading many manuals and I finally able to get the Varnish vcl file.

If you are configuring first time Varnish,read my this earlier post

https://sharadchhetri.com/2013/09/25/how-to-setup-varnish-web-accelerator-in-centos-and-rhel/

After finish the above given setup,edit the /etc/varnish/default.vcl file and paste the below given contents

Note: Change the port no. 8880 as you want to apache run on. If you select port no. 8880 then you have run apache in port no. 8880

Below is my default.vcl file for wordpress.

backend default {
  .host = "127.0.0.1";
  .port = "8880";
}
##################################################
sub vcl_recv {
    if (req.restarts == 0) {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =
            req.http.X-Forwarded-For + ", " + client.ip;
        } else {
            set req.http.X-Forwarded-For = client.ip;
        }
    }
    if (req.request == "PURGE") {
        if ( client.ip != "192.241.190.251") {
            error 405 "Not allowed.";
        }
        return (lookup);
    }
    if (req.request != "GET" &&
        req.request != "HEAD" &&
        req.request != "PUT" && 
        req.request != "POST" &&
        req.request != "TRACE" &&
        req.request != "OPTIONS" &&
        req.request != "DELETE") {
            return (pipe);
    }
    if (req.request != "GET" && req.request != "HEAD") {
        return (pass);
    }
    if (!(req.url ~ "wp-(login|admin)") &&
        !(req.url ~ "&preview=true" ) ) {
        unset req.http.cookie;
    }
 
    if (req.http.Authorization || req.http.Cookie) {
        return (pass);
    }
    return (lookup);
}

sub vcl_fetch {
    if (!(req.url ~ "wp-(login|admin)")) {
        unset beresp.http.set-cookie;
        set beresp.ttl = 96h;
    }
 
    if (beresp.ttl <= 0s ||
        beresp.http.Set-Cookie ||
        beresp.http.Vary == "*") {
            set beresp.ttl = 120 s;
            return (hit_for_pass);
    }
    return (deliver);
}
 
sub vcl_hit {
    if (req.request == "PURGE") {
        purge;
        error 200 "Purged.";
    }
    return (deliver);
}
 
sub vcl_miss {
    if (req.request == "PURGE") {
        purge;
        error 200 "Purged.";
    }
    return (fetch);
}
 

After editing the default.vcl file,restart the varnish

/etc/init.d/varnish restart

Checking is Varnish cacheing or not

Yes,it was working

See the below output

linux@tuxworld:~$  curl -I https://sharadchhetri.com
HTTP/1.1 200 OK
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Mobilized-By: WordPress Mobile Pack 1.2.5
Content-Type: text/html; charset=UTF-8
Content-Length: 50037
Accept-Ranges: bytes
Date: Mon, 30 Sep 2013 15:37:36 GMT
X-Varnish: 1302477386 1302477385
Age: 3
Via: 1.1 varnish
Connection: keep-alive

linux@tuxworld:~$ 

After using Varnish,my blog speed is increased.

Do'nt be greedy, share the knowledge!

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Related

Filed Under: Linux, web accelerator Tagged With: varnish

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Help To Needy

If you like our posts and tutorials, please support/donate to ANY “Open Source Project” or do some Charity work. Hope this will make someone happy in this world. Drop me an email if you want to inspire others!

Thank You!

Follow Us

  • Facebook
  • Twitter
  • GitHub
  • YouTube

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Top Posts & Pages

  • How to fix read only USB pen drive in Ubuntu
  • How to delete mail queue in Postfix
  • How to start / stop / restart / reload iptables on CentOS 7 / RHEL 7
  • How to find absolute path of command on Linux / Unix : which command
  • Install KVM on Ubuntu 14.04 LTS Desktop
  • type command : display information about command type on Linux
  • How to zip the directory in linux with command line
  • How to set hostname and FQDN on CentOS 7 and RHEL 7
  • 4 different commands to check the load average in linux
  • CentOS 7 / RHEL 7 : change OpenSSH port number ( SELINUX enabled )

Recent Posts

  • Install and setup maven in Linux for Jenkins
  • How to setup Jenkins Credentials for Git repo access
  • How to manage Jenkins Credentials
  • Managing Jenkins plugins from command line and GUI
  • How to create Jenkins user by command line and GUI

Footer

Sharad Chhetri is an experienced Linux - Cloud Engineer & freelancer. Working on Open Source Technology since RHEL 4.0 (Red Hat Enterprise Linux). He loves sharing the knowledge which earned from real scenarios. Don't be surprised if you find him in technology seminars and meetup groups. You can contact him on email for freelance projects at admin@sharadchhetri.com. Read More…

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Our GitHub Repo

sharadchhetri @ GitHub
  • java-samples
    Java Sample Project For Tutorial
    December 25, 2018 - 2:29 pm UTC
  • misc
    OpenSSH rpm created from tar ball
    November 21, 2018 - 3:12 am UTC
  • scripts
    Cassandra Backup Script
    November 21, 2018 - 3:09 am UTC
  • packer
    Packer : Create server images in automated way
    November 21, 2018 - 3:08 am UTC
  • Nagios
    My Nagios custom plugins
    November 21, 2018 - 3:07 am UTC

Recent Comments

  • Sharad Chhetri on CentOS 7 / RHEL 7 : change OpenSSH port number ( SELINUX enabled )
  • Dave on CentOS 7 / RHEL 7 : change OpenSSH port number ( SELINUX enabled )
  • Prafulla S on Install Shotcut on Ubuntu 16.04 LTS desktop
  • Sujata on Install Telnet Server on CentOS 7 / RHEL 7
  • kishen sharma on How to install redis server on CentOS 7 / RHEL 7
  • Sharad Chhetri on Secondary Logging : save all users history command output as log
  • Anand on Secondary Logging : save all users history command output as log
  • Sharad Chhetri on Install redis 3.0 from source on Ubuntu 14.04 / CentOS 7 / RHEL 7

Copyright © 2009 - 2019 · All Rights Reserved sharadchhetri.com · · Privacy Policy ·
· sitemap.xml · ·The content is copyrighted to sharadchhetri.com and may not be reproduced on other websites without our permission. ·