Created
June 8, 2018 07:36
-
-
Save cengizhancaliskan/afa3f5d9bd760b7162e21831db869d16 to your computer and use it in GitHub Desktop.
varnish symfony
This file contains hidden or 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
vcl 4.0; | |
import directors; | |
backend app2 { | |
.host = "10.135.19.167"; | |
.port = "8080"; | |
} | |
backend app3 { | |
.host = "10.135.40.246"; | |
.port = "8080"; | |
} | |
sub vcl_init { | |
new vdir = directors.round_robin(); | |
vdir.add_backend(app2); | |
vdir.add_backend(app3); | |
} | |
sub vcl_recv { | |
set req.backend_hint = vdir.backend(); | |
if (req.http.X-Forwarded-Proto == "https" ) { | |
set req.http.X-Forwarded-Port = "443"; | |
} else { | |
set req.http.X-Forwarded-Port = "80"; | |
} | |
// Add a Surrogate-Capability header to announce ESI support. | |
set req.http.Surrogate-Capability = "KingKong=ESI/1.0"; | |
// Remove all cookies except the session ID. | |
if (req.http.Cookie && !req.http.X-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, "^[; ]+|[; ]+$", ""); | |
# Clean empty Cookie header | |
if (req.http.Cookie == "") { | |
// If there are no more cookies, remove the header to get page cached. | |
unset req.http.Cookie; | |
} | |
# Save cookie to X-Cookie header | |
set req.http.X-Cookie = req.http.Cookie; | |
} | |
if(req.http.X-Cookie) { | |
set req.http.Cookie = req.http.X-Cookie; | |
} | |
} | |
sub vcl_backend_response { | |
set beresp.ttl = 24h; | |
set beresp.grace = 1h; # sonra buda 24h olacak | |
// Check for ESI acknowledgement and remove Surrogate-Control header | |
if (beresp.http.Surrogate-Control ~ "ESI/1.0") { | |
unset beresp.http.Surrogate-Control; | |
set beresp.do_esi = true; | |
} | |
} | |
sub vcl_deliver { | |
if (req.http.X-Purger) { | |
set resp.http.X-Purger = req.http.X-Purger; | |
} | |
if (obj.hits > 0) { | |
set resp.http.X-Cache = "HIT"; | |
} else { | |
set resp.http.X-Cache = "MISS"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment