The document introduces Varnish, an open-source web application accelerator. It was initially developed in 2005 by a Norwegian newspaper to improve website performance. Varnish acts as a reverse proxy cache in front of web servers to cache and serve repeated requests, improving performance. The document further explains Varnish concepts like VCL and Grace mode.
161.
sub vcl_recv{
# Set Client Ip
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
# cache 하지 않는 URL 설정
if( req.url ~ /.*.json || req.url ~ /request.jsp ){
set req.backend = backend1;
return (pipe);
}
# backend server 설정
set req.backend = directorA;
set req.grace = 30m;
# cache 대상 URL 설정
if (req.url ~ /index.jsp || req.url ~ “home.jsp“ ){
return (lookup);
}
return (pipe);
}
190.
sub vcl_deliver{
if (obj.hits 0) { # cache에서 hit한 경우
set resp.http.X-Varnish-Cache = HIT;
}
else {
set resp.http.X-Varnish-Cache = MISS;
}
set resp.http.connection = close; # keep-alive off
}
sub vcl_pipe{
set bereq.http.connection = close; # keep-alive off
}
sub vcl_error
{
# 세번 restart 시도
if ( req.restarts 3 ) {
return(restart);
}
# error 페이지로 redirect
set obj.http.location = http://domain_name/error.jsp;
set obj.status = 302;
return( deliver ) ;
}