Last active
July 20, 2020 09:59
-
-
Save timglabisch/7016689 to your computer and use it in GitHub Desktop.
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 is a basic VCL configuration file for varnish. See the vcl(7) | |
# man page for details on VCL syntax and semantics. | |
# | |
backend default { | |
.host = "127.0.0.1"; | |
.port = "80"; | |
# health check: every 5 secs, sliding window of 5 checks of which 3 must be good | |
#.probe = { | |
# .url = "/index.php"; | |
# .interval = 5s; | |
# .timeout = 1s; | |
# .window = 5; | |
# .threshold = 3; | |
#} | |
} | |
# another backend: | |
#backend nodejs { | |
# .host = "127.0.0.1"; | |
# .port = "8001"; | |
#} | |
sub vcl_deliver { | |
if (obj.hits > 0) { | |
set resp.http.X-Cache = "HIT"; | |
} else { | |
set resp.http.X-Cache = "MISS"; | |
} | |
} | |
sub vcl_recv { | |
# just deal with GET, so POST Requests can add or remove the SessionId | |
if (req.request != "GET") { | |
return (pipe); | |
} | |
# add uncacheable url's, | |
if (req.url ~ "^/admin") { | |
return (pipe); | |
} | |
# everytime cache static assets... | |
if (req.url ~ "\.(png|gif|jpg|swf|css|js|zip|pdf|flv|mp3|txt)$") { | |
unset req.http.Cookie; | |
return(lookup); | |
} | |
# cookie handling for pimcore frontend step 1 | |
if(req.http.Cookie ~ "(pimcore_admin_sid|PHPSESSID)" || req.url ~ "(PHPSESSID|pimcore_admin_sid)" || req.url ~ "nocache") | |
{ | |
return (pipe); | |
} | |
# everything here is cacheable | |
unset req.http.Cookie; | |
} | |
sub vcl_fetch { | |
# do not cache errors :) | |
if(beresp.status != 200) { | |
return(hit_for_pass); | |
} | |
if (req.http.Authorization) { | |
return(hit_for_pass); | |
} | |
# cache static assets, ignore cookie here | |
if (req.url ~ "\.(png|gif|jpg|swf|css|js|zip|pdf|flv|mp3)$") { | |
set beresp.ttl = 20m; | |
set beresp.grace = 2h; | |
set beresp.http.X-TTL = beresp.ttl; | |
set beresp.http.X-GRACE = beresp.grace; | |
unset req.http.Cookie; | |
return (deliver); | |
} | |
if (beresp.http.set-cookie ~ "(PHPSESSID|pimcore_admin_sid)" || req.url ~ "nocache") { | |
return(hit_for_pass); | |
} | |
# enable zip | |
if (beresp.http.content-type ~ "text") { | |
set beresp.do_gzip = true; | |
} | |
# enable zip for css / text | |
if (req.url ~ "\.(js|css)$") { | |
set beresp.do_gzip = true; | |
} | |
unset beresp.http.expires; | |
unset beresp.http.Cache-Control; | |
unset beresp.http.Age; | |
# everything now is cacheable | |
set beresp.grace = 2h; | |
set beresp.ttl = 420s; | |
# add this for every special url | |
if(req.url ~ "some_urls") { | |
set beresp.ttl = 420s; | |
} | |
# for debuging | |
set beresp.http.X-TTL = beresp.ttl; | |
set beresp.http.X-GRACE = beresp.grace; | |
return (deliver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment