Click here to load reader
Upload
agate-studio
View
147
Download
3
Embed Size (px)
Citation preview
@agatestudio
Varnish
Aswin
Knight
Agate Studio
@agatestudio@agatestudio@agatestudio
VARNISHAswin Juari
@agatestudio@agatestudio@agatestudio
Overview
• What is varnish
• Why Varnish
• What to do
@agatestudio@agatestudio@agatestudio
What
• A Proxy
• A Load balancer
• An Http Accelerator which accelerates by caching output from apache/another web server.
@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
@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";
}
@agatestudio@agatestudio@agatestudio
What to do
• Request Scheme Varnish:
Request Received vcl_recv() vcl_pass() vcl_fetch() vcl_deliver() Request Completed
@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);
}
@agatestudio@agatestudio@agatestudio
What to dosub vcl_fetch {
# Our cache TTL
set beresp.ttl = 1m;
return(deliver);
}
Set Cache not older than 1 minute
@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
@agatestudio@agatestudio@agatestudio
Sources
• https://www.varnish-cache.org/docs/4.0/tutorial/index.html
• http://ellislab.com/blog/entry/making-sites-fly-with-varnish
• https://www.varnish-software.com/system/files/web_downloads/varnish-book.pdf