Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vincent Bechu
slapos
Commits
0dcf1714
Commit
0dcf1714
authored
Jun 27, 2013
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify and improve varnish configuration.
parent
f3ef773f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
84 deletions
+40
-84
slapos/recipe/generic_varnish/template/default.vcl.in
slapos/recipe/generic_varnish/template/default.vcl.in
+40
-84
No files found.
slapos/recipe/generic_varnish/template/default.vcl.in
View file @
0dcf1714
...
@@ -33,149 +33,105 @@ sub vcl_recv {
...
@@ -33,149 +33,105 @@ sub vcl_recv {
req.request != "PURGE" &&
req.request != "PURGE" &&
req.request != "DELETE") {
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
/* Non-RFC2616 or CONNECT which is weird. */
return(pipe);
return
(pipe);
}
}
# Pass anything other than GET and HEAD
and PURGE
directly.
# Pass anything other than GET and HEAD directly.
if (req.request != "GET" && req.request != "HEAD"
&& req.request != "PURGE"
) {
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
unset req.http.If-Modified-Since;
return(pass);
return
(pass);
}
}
if (req.http.Authorization) {
if (req.http.Authorization) {
/* Not cacheable by default */
/* Not cacheable by default */
unset req.http.If-Modified-Since;
return (pass);
return (pass);
}
}
#
no need to have cookies for the
resources
#
No need to have cookies for static
resources
if (req.url ~ "\.(css|
js|ico
)$") {
if (req.url ~ "\.(css|
gif|ico|jpg|js|png
)$") {
unset req.http.
c
ookie;
unset req.http.
C
ookie;
}
}
#
r
emove bogus cookies
#
R
emove bogus cookies
if (req.http.Cookie) {
if (req.http.Cookie) {
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__ac_name=\x22\x22;? *", "\1");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__ac_name=\x22\x22;? *", "\1");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__ac=\x22Og.3D.3D\x22;? *", "\1");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__ac=\x22Og.3D.3D\x22;? *", "\1");
}
}
if (req.http.Cookie == "") {
if (req.http.Cookie == "") {
remove
req.http.Cookie;
unset
req.http.Cookie;
}
}
if (req.http.Cookie && req.http.Cookie ~ "(^|; ) *__ac=") {
if (req.http.Cookie && req.http.Cookie ~ "(^|; ) *__ac=") {
/* Not cacheable for authorised users,
unset req.http.If-Modified-Since;
but KM images are cacheable */
if (!(req.url ~ "/km_img/.*\.(png|gif)$")) {
return (pass);
return (pass);
}
}
}
# XXX Is it OK to remove this of all the case?
remove req.http.Set-Cookie;
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
# unkown algorithm
remove req.http.Accept-Encoding;
}
}
# We do not care about Accept-Language, this is url controlled
remove req.http.Accept-Language;
## XXX login form can defer based on __ac_name cookie value
# We do not care about Accept-Encoding, because we don't use varnish as the front most HTTP server.
if (req.url ~ "/(login_form|WebSite_viewLoginDialog)($|\?)") {
unset req.http.Accept-Encoding;
return (pass);
}
if (req.backend.healthy) {
if (req.backend.healthy) {
set req.grace = 1h;
set req.grace = 1h;
} else {
} else {
set req.grace = 1w;
set req.grace = 1w;
}
}
return(lookup);
return
(lookup);
}
}
# Creates the varnish cache key by the url
# Creates the varnish cache key by the url
sub vcl_hash {
sub vcl_hash {
# We use url only for hash.
hash_data(req.url);
hash_data(req.url);
return(hash);
return
(hash);
}
}
# Called after a cache lookup if the requested document was found in the cache
# Called after a cache lookup if the requested document was found in the cache
sub vcl_hit {
sub vcl_hit {
# According Vary Header do not return those headers
return (deliver);
remove req.http.Accept-Language;
remove req.http.Accept-Encoding;
remove req.http.Cookie;
return(deliver);
}
}
# Called after a cache lookup if the requested document was not found in the cache
# Called after a cache lookup if the requested document was not found in the cache
sub vcl_miss {
sub vcl_miss {
return(fetch);
return
(fetch);
}
}
# Called after a document has been successfully retrieved from the backend
# Called after a document has been successfully retrieved from the backend
sub vcl_fetch {
sub vcl_fetch {
# we only cache 200 (OK) and 304 (Not Modified) responses.
# Unset Expires that is always overridden by Cache-Control.
if (beresp.status != 200 && beresp.status != 304) {
unset beresp.http.Expires;
set beresp.ttl = 0s;
}
# Unset Pragma header that is obsolete.
unset beresp.http.Pragma;
if (beresp.http.cache-control ~ "no-cache") {
# We only cache 200 (OK) and 304 (Not Modified) responses.
if (beresp.status != 200 && beresp.status != 304) {
set beresp.ttl = 0s;
set beresp.ttl = 0s;
}
}
if (beresp.ttl == 0s) {
# If max-age is 0 or not set, we want no browser cache.
unset beresp.http.expires;
if (beresp.ttl <= 0s) {
set beresp.http.cache-control = "no-cache";
set beresp.http.Cache-Control = "no-store";
return(hit_for_pass);
# Mark as hit_for_pass for the next 2 minutes.
set beresp.ttl = 120s;
return (hit_for_pass);
}
}
#
w
e don't care haproxy's cookie.
#
W
e don't care haproxy's cookie.
if (beresp.http.Set-Cookie && beresp.http.Set-Cookie !~ "^SERVERID=[^;]+; path=/$") {
if (beresp.http.Set-Cookie && beresp.http.Set-Cookie !~ "^SERVERID=[^;]+; path=/$") {
return(hit_for_pass);
return (hit_for_pass);
}
} else {
unset beresp.http.Set-Cookie;
if (req.url ~ "\.(css|js|ico)$") {
unset beresp.http.set-cookie;
set beresp.http.cache-control = regsub(beresp.http.cache-control, "^", "public,");
set beresp.http.cache-control = regsub(beresp.http.cache-control, ",$", "");
}
# remove some headers added by caching policy manager to avoid
# '304 Not Modified' in case of login <-> logout switching.
if (beresp.http.content-type ~ "^text/html") {
unset beresp.http.last-modified;
}
}
# We set long enough grace for cachable objects.
set beresp.grace = 1w;
set beresp.grace = 1w;
/* Never send request to backend even if client ask refreshed content */
if (beresp.ttl > 0s) {
/* Setup grace period for 30days for all cacheable contents */
set beresp.grace = 30d;
# /* Set the clients TTL on this object */
# set beresp.http.cache-control = "max-age = 300";
/* Set how long Varnish will keep it */
set beresp.ttl = 1w;
/* marker for vcl_deliver to reset Age: */
set beresp.http.magicmarker = "1";
}
return(deliver);
return
(deliver);
}
}
# Called before a cached object is delivered to the client
# Called before a cached object is delivered to the client
sub vcl_deliver {
sub vcl_deliver {
if (resp.http.magicmarker) {
/* Remove the magic marker */
unset resp.http.magicmarker;
/* By definition we have a fresh object */
set resp.http.age = "0";
}
if (obj.hits > 0) {
if (obj.hits > 0) {
set resp.http.X-Cache = obj.hits;
set resp.http.X-Cache = obj.hits;
} else {
} else {
set resp.http.X-Cache = "MISS";
set resp.http.X-Cache = "MISS";
}
}
return(deliver);
return
(deliver);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment