11

Click here to load reader

Varnish by Aswin

Embed Size (px)

Citation preview

Page 1: Varnish by Aswin

@agatestudio

Varnish

Aswin

Knight

Agate Studio

Page 2: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

VARNISHAswin Juari

Page 3: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

Overview

• What is varnish

• Why Varnish

• What to do

Page 4: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

What

• A Proxy

• A Load balancer

• An Http Accelerator which accelerates by caching output from apache/another web server.

Page 5: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

Why

• So, instead of web server doing the same process and the same result, why not caching the result and pass to user.

• However, remember that:

– Your data might be obsolete/incorrect

– So, you must configure varnish correctly.• Determine which one that can be processed by varnish

• Or the one that must be checked by Web Server

Page 6: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

What to do

• Configure Varnish at port 80, Apache at another port (e.g. 8080)

vcl 4.0;

backend default {

.host = "127.0.0.1";

.port = "8080";

}

Page 7: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

What to do

• Request Scheme Varnish:

Request Received vcl_recv() vcl_pass() vcl_fetch() vcl_deliver() Request Completed

Page 8: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

What to do

Pass: Send it to apache

Lookup: try to get it from cache

sub vcl_recv {

# Set the URI of your system directory

if (req.url ~ '^/admin/' ||

req.url ~ 'ACT=' ||

req.request == 'POST')

{

return (pass);

}

#unset user cookie from being saved to

cache

unset req.http.Cookie;

return(lookup);

}

Page 9: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

What to dosub vcl_fetch {

# Our cache TTL

set beresp.ttl = 1m;

return(deliver);

}

Set Cache not older than 1 minute

Page 10: Varnish by Aswin

@agatestudio@agatestudio@agatestudio

Varnish vs NginX

• Varnish cannot do https request :D. Meanwhile nginxcan do that.

• Others said that better we use nginx only :D

– Config varnish, nginx, apache is not worth of time

– Nginx + PHP + DB + APC/Memcache is more than enough

– So, it depends on App in the Server