#backend vhost
backend myvarnishbackend {
.host = "192.168.8.101";
.port = "8080";
}
#acl
acl purge {
"localhost";
"127.0.0.1";
}
sub vcl_recv {
if (req.http.Accept-Encoding)
{
if (req.url ~ "\.(ico|jpg|png|gif|jpeg|flv)$" ) {
remove req.http.Accept-Encoding;
remove req.http.Cookie;
}
else if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
}
else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
}
else {
remove req.http.Accept-Encoding;
}
}
#
if (req.http.host ~ "^(www.)?linux.net$")
{
set req.backend = myvarnishbackend;
}
else {
error 404 "This website is maintaining or not exist!";
}
#
if (req.request == "PURGE") {
if (!client.ip ~purge)
{
error 405 "Not Allowed";
}
return(lookup);
}
#...GET...url...jpg,png,gif. ..cookie
if (req.request == "GET" && req.url ~ "\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|gz|tgz|bz2|tbz|mp3|ogg|mp4|flv|f4v|pdf)$") {
unset req.http.cookie;
}
#..GET...url.php....cache....
if (req.request == "GET" && req.url ~ "\.(php)$") {
return (pass);
}
#........pipe..
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE")
{
return (pipe);
}
#..GET .HEAD.....
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
if (req.http.Authorization) {
return (pass);
}
return (lookup);
}
#..url+host hash......
sub vcl_hash {
set req.hash += req.url;
if (req.http.host) {
set req.hash += req.http.host;
} else {
set req.hash += server.ip;
}
return (hash);
}
# .....purge .....
sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged";
}
return (deliver);
}
sub vcl_pipe {
return (pipe);
}
sub vcl_pass {
return (pass);
}
#fetch
sub vcl_fetch {
if (!beresp.cacheable) {
return (pass);
}
if (beresp.http.Set-Cookie) {
return (pass);
}
return (deliver);
}
sub vcl_deliver {
return (deliver);
}
转载于:https://blog.51cto.com/cwind/1130242