• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content







Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Varnish Varnish Presentation Transcript

    • Varnish
    • What is a reverse proxy? Forward Proxy Reverse Proxyhttp://en.wikipedia.org/wiki/Proxy_server
    • Install Varnish curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add - echo "deb http://repo.varnish-cache.org/ubuntu/ $(lsb_release -s -c) varnish-3.0" >> /etc/apt/sources.list apt-get update apt-get install varnishhttps://www.varnish-cache.org/installation/ubuntu
    • Concept of Backend Servers# /etc/varnish/default.vcl Backend Servers provide thebackend default { content to varnish .host = "" .port = "80"}
    • Start Varnish varnishd -F -f /etc/varnish/default.vcl -a Run in the foregroud-f /etc/varnish/default.vcl Use our default config file-a Listen for requests on port 8080
    • VCLVarnish Configuration LanguageUsed to configure how varnish handles requestsCan be used to manipulate headers
    • How Varnish knows what to cache?Varnish will not cache: An object coming from the backend server with a Set-Cookieheader. A request coming from the client with a cookie header
    • Purging the cache# /etc/varnish/default.vclacl purge { Simple script that will allow only "localhost"; requests from localhost to purge the}sub vcl_recv { cache if (req.request == "PURGE") { if (!client.ip ~ purge) { error 405 "Not allowed."; PURGE is a request method, just like } return (lookup); GET or POST }}sub vcl_hit { if (req.request == "PURGE") { purge; error 200 "Purged."; }}sub vcl_miss { if (req.request == "PURGE") { purge; error 200 "Purged."; }}
    • Not just a HTTP Accelerator Varnish can be setup as a load balancer to distribute therequests across multiple servers
    • Multiple Backends# /etc/varnish/default.vcl You can define as many backendsbackend server01 { as needed .host = ""; .port = "8080"; Each can be different hosts and} different portsbackend server02 { .host = ""; .port = "8080";}
    • Directors# /etc/varnish/default.vcl Directors are groups ofdirector default round-robin { backends { .backend = "server01"; } { .backend = "server02"; }}
    • Health Checks# /etc/varnish/varnish. urlvcl URL to checkbackend server01 { interval .host = ""; Poll every X .port = "8080"; timeout .probe { Timeout after X .url = "/"; window .interval = 5s; The past X requests .timeout = 1s; threshold .window = 5; How many good probes .threshold = 3; }}
    • High Availability● Grace Mode ○ Instructs Varnish to keep objects past TTL● Saint Mode ○ Try another server or serve stale content● God Mode ○ Not yet implemented
    • Grace Mode Example# /etc/varnish/default.vcl set beresp.gracesub vcl_fetch { Instructs Varnish to store set beresp.grace = 30m; objects for n minutes}sub vcl_recv { set req.grace if (!req.backend.healthy) { Instructs Varnish to serve set req.grace = 5m; objects that are n seconds old } else { set req.grace = 15s; }}
    • Saint Mode Example# /etc/varnish/default.vcl set beresp.saintmodesub vcl_fetch { How long before if (beresp.status == 500) { Varnish can ask that set beresp.saintmode = 10s; server for the URL again. restart; } set beresp.grace set beresp.grace = 5m; Instructs Varnish to} store objects for n minutes
    • Questions?Documentation TOChttps://www.varnish-cache.org/docs/3.0/index.htmlReference Manualhttps://www.varnish-cache.org/docs/3.0/reference/index.htmlRandom Outburstshttps://www.varnish-cache.org/docs/3.0/phk/index.html