Difference between revisions of "Setup Varnish Cache"

From Brian Nelson Ramblings
Jump to: navigation, search
(Additional Articles)
(Make Varnish start on Boot)
Line 22: Line 22:
  
 
  /etc/init.d/varnish start
 
  /etc/init.d/varnish start
 +
 +
===Configure Varnish to use Port 80===
  
 
The default installation of Varnish will start off listening to port 6081
 
The default installation of Varnish will start off listening to port 6081
Line 32: Line 34:
  
 
  VARNISH_LISTEN_PORT=80
 
  VARNISH_LISTEN_PORT=80
 +
 +
===Configure http/Apache to port 81===
  
 
Now if you have httpd already started will you will want to stop and make httpd listen on another port, example port 81
 
Now if you have httpd already started will you will want to stop and make httpd listen on another port, example port 81
Line 42: Line 46:
  
 
Now apache will be listing on port 81 and varnish will listen on port 80
 
Now apache will be listing on port 81 and varnish will listen on port 80
 +
 +
===Configure Varnish to Use Apache port 81===
  
 
Now you will want to edit you default.vcl file, to tell it use 127.0.0.1:81.
 
Now you will want to edit you default.vcl file, to tell it use 127.0.0.1:81.
Line 58: Line 64:
 
  /etc/init.d/varnish restart
 
  /etc/init.d/varnish restart
  
 +
===Lets Verify Everything is Correct===
 
Now we check and make sure httpd is listen on port 81 and varnish is listening on port 80
 
Now we check and make sure httpd is listen on port 81 and varnish is listening on port 80
  

Revision as of 00:13, 19 January 2014

Setting up Varnish Cache with default.vcl

What is Varnish Cache?

Varnish is a web application accelerator. You install it in front of your web application and it will speed it up significantly.

Once finished the reader should have a basic Varnish 3.0 cache up and running with the default configuration.

Install Varnish YUM Repository

rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm

Install Varnish with Yum

yum install varnish -y

Make Varnish start on Boot

chkconfig varnish on

Now the basic Varnish install is complete, now lets start it

/etc/init.d/varnish start

Configure Varnish to use Port 80

The default installation of Varnish will start off listening to port 6081

You will want to adjust this to listen on port 80 so that it will cache incoming web requests.

vim /etc/sysconfig/varnish

Adjust the following value to port 80

VARNISH_LISTEN_PORT=80

Configure http/Apache to port 81

Now if you have httpd already started will you will want to stop and make httpd listen on another port, example port 81

sed -i 's/80/81/g' /etc/httpd/conf/httpd.conf

Now restart apache so it will start listen on port 81

/etc/init.d/httpd restart && /etc/init.d/varnish restart

Now apache will be listing on port 81 and varnish will listen on port 80

Configure Varnish to Use Apache port 81

Now you will want to edit you default.vcl file, to tell it use 127.0.0.1:81.

vim /etc/varnish/default.vcl

Change backend to use port 81, by default its set to port 80.

 backend default {
  .host = "127.0.0.1";
  .port = "81";
}

Now one last varnish restart, and you are up and running with the default varnish installation

/etc/init.d/varnish restart

Lets Verify Everything is Correct

Now we check and make sure httpd is listen on port 81 and varnish is listening on port 80

netstat -nptl | grep -E '80|81'

Varnish Setup

Additional Articles