-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Varnish as a cache server to improve response times for heavy l…
…oads
- Loading branch information
1 parent
abad96d
commit 22ce5c9
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
vcl 4.1; | ||
|
||
backend default { | ||
.host = "php"; | ||
.port = "9000"; | ||
} | ||
|
||
sub vcl_recv { | ||
set req.backend_hint = vdir.backend(); | ||
|
||
if (req.http.Cookie) { | ||
set req.http.Cookie = ";" + req.http.Cookie; | ||
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";"); | ||
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1="); | ||
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); | ||
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); | ||
|
||
if (req.http.Cookie == "") { | ||
unset req.http.Cookie; | ||
} | ||
} | ||
|
||
if (req.method != "GET" && | ||
req.method != "HEAD" && | ||
req.method != "PUT" && | ||
req.method != "POST" && | ||
req.method != "TRACE" && | ||
req.method != "OPTIONS" && | ||
req.method != "DELETE" | ||
) { | ||
return (pipe); | ||
} | ||
|
||
if (req.http.Authorization) { | ||
return (pass); | ||
} | ||
|
||
if (req.method != "GET" && req.method != "HEAD") { | ||
return (pass); | ||
} | ||
} | ||
|
||
sub vcl_backend_response { | ||
if (beresp.status >= 400 && beresp.status < 600) { | ||
set beresp.uncacheable = true; | ||
return (deliver); | ||
} | ||
|
||
set beresp.ttl = 5m; | ||
|
||
return (deliver); | ||
} | ||
|
||
sub vcl_deliver { | ||
if (obj.hits > 0) { | ||
set resp.http.X-Cache = "HIT"; | ||
} else { | ||
set resp.http.X-Cache = "MISS"; | ||
} | ||
|
||
set resp.http.X-Cache-Hits = obj.hits; | ||
} |