Varnish + Wordpress + Nginx - Prevent no-store no-cache must-revalidate headers
We launched a web app about a week ago, experienced a heavy load spike and were down for almost 2 hours. I won't mention the company by name, but we were leaning on them for recommendations to prevent this exact thing.
They said that since we were using Varnish, we could handle the traffic influx quite easily. However, we didn't verify caching was working as intended. It was not.
TLDR: Our web app is sending Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 headers with requests and there's no indication of why that is.
Where can I look to prevent these headers from being sent?
PHP: 5.6
Nginx: 1.4.6
Varnish: 1.1
Wordpress: 4.6.12
Timber: 1.2.4
The linux admins we're working with have said they scoured the configs and haven't found anything specifying those headers except for AJAX requests.
#dont cache ajax requests
if(req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)")
Here's a curl from Pre-launch when we correctly configured Varnish to cache after forcing HTTPS(force-https plugin) on the site:
$ curl -Ik -H'X-Forwarded-Proto: *************
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Server: *****
Date: Sat, 03 Nov 2018 22:36:43 GMT
X-Varnish: 53061104
Age: 0
Via: 1.1 varnish
Connection: keep-alive
And from post launch:
curl -ILk ***********
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
X-Varnish: 691817320
Vary: Accept-Encoding
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type: text/html; charset=UTF-8
X-Server: ****
Date: Mon, 19 Nov 2018 19:17:02 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Transfer-Encoding: chunked
Accept-Ranges: bytes
Via: 1.1 varnish
Connection: Keep-Alive
Set-Cookie: X-Mapping-fjhppofk=33C486CB71216B67C5C5AB8F5E63769E; path=/
Age: 0
Force-https plugin: We activated this, updated the Varnish config to avoid a redirect loop and confirmed it was working a week prior to launch.
Plugins: These did not change, except for force-https.
Web App: It's an updated version of the previous app, complete redesign but nothing in the app from what I can tell is specifying no-store no-cache headers to be sent.
Where should I start? Thanks!
wordpress nginx varnish varnish-vcl timber
add a comment |
We launched a web app about a week ago, experienced a heavy load spike and were down for almost 2 hours. I won't mention the company by name, but we were leaning on them for recommendations to prevent this exact thing.
They said that since we were using Varnish, we could handle the traffic influx quite easily. However, we didn't verify caching was working as intended. It was not.
TLDR: Our web app is sending Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 headers with requests and there's no indication of why that is.
Where can I look to prevent these headers from being sent?
PHP: 5.6
Nginx: 1.4.6
Varnish: 1.1
Wordpress: 4.6.12
Timber: 1.2.4
The linux admins we're working with have said they scoured the configs and haven't found anything specifying those headers except for AJAX requests.
#dont cache ajax requests
if(req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)")
Here's a curl from Pre-launch when we correctly configured Varnish to cache after forcing HTTPS(force-https plugin) on the site:
$ curl -Ik -H'X-Forwarded-Proto: *************
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Server: *****
Date: Sat, 03 Nov 2018 22:36:43 GMT
X-Varnish: 53061104
Age: 0
Via: 1.1 varnish
Connection: keep-alive
And from post launch:
curl -ILk ***********
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
X-Varnish: 691817320
Vary: Accept-Encoding
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type: text/html; charset=UTF-8
X-Server: ****
Date: Mon, 19 Nov 2018 19:17:02 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Transfer-Encoding: chunked
Accept-Ranges: bytes
Via: 1.1 varnish
Connection: Keep-Alive
Set-Cookie: X-Mapping-fjhppofk=33C486CB71216B67C5C5AB8F5E63769E; path=/
Age: 0
Force-https plugin: We activated this, updated the Varnish config to avoid a redirect loop and confirmed it was working a week prior to launch.
Plugins: These did not change, except for force-https.
Web App: It's an updated version of the previous app, complete redesign but nothing in the app from what I can tell is specifying no-store no-cache headers to be sent.
Where should I start? Thanks!
wordpress nginx varnish varnish-vcl timber
add a comment |
We launched a web app about a week ago, experienced a heavy load spike and were down for almost 2 hours. I won't mention the company by name, but we were leaning on them for recommendations to prevent this exact thing.
They said that since we were using Varnish, we could handle the traffic influx quite easily. However, we didn't verify caching was working as intended. It was not.
TLDR: Our web app is sending Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 headers with requests and there's no indication of why that is.
Where can I look to prevent these headers from being sent?
PHP: 5.6
Nginx: 1.4.6
Varnish: 1.1
Wordpress: 4.6.12
Timber: 1.2.4
The linux admins we're working with have said they scoured the configs and haven't found anything specifying those headers except for AJAX requests.
#dont cache ajax requests
if(req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)")
Here's a curl from Pre-launch when we correctly configured Varnish to cache after forcing HTTPS(force-https plugin) on the site:
$ curl -Ik -H'X-Forwarded-Proto: *************
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Server: *****
Date: Sat, 03 Nov 2018 22:36:43 GMT
X-Varnish: 53061104
Age: 0
Via: 1.1 varnish
Connection: keep-alive
And from post launch:
curl -ILk ***********
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
X-Varnish: 691817320
Vary: Accept-Encoding
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type: text/html; charset=UTF-8
X-Server: ****
Date: Mon, 19 Nov 2018 19:17:02 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Transfer-Encoding: chunked
Accept-Ranges: bytes
Via: 1.1 varnish
Connection: Keep-Alive
Set-Cookie: X-Mapping-fjhppofk=33C486CB71216B67C5C5AB8F5E63769E; path=/
Age: 0
Force-https plugin: We activated this, updated the Varnish config to avoid a redirect loop and confirmed it was working a week prior to launch.
Plugins: These did not change, except for force-https.
Web App: It's an updated version of the previous app, complete redesign but nothing in the app from what I can tell is specifying no-store no-cache headers to be sent.
Where should I start? Thanks!
wordpress nginx varnish varnish-vcl timber
We launched a web app about a week ago, experienced a heavy load spike and were down for almost 2 hours. I won't mention the company by name, but we were leaning on them for recommendations to prevent this exact thing.
They said that since we were using Varnish, we could handle the traffic influx quite easily. However, we didn't verify caching was working as intended. It was not.
TLDR: Our web app is sending Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 headers with requests and there's no indication of why that is.
Where can I look to prevent these headers from being sent?
PHP: 5.6
Nginx: 1.4.6
Varnish: 1.1
Wordpress: 4.6.12
Timber: 1.2.4
The linux admins we're working with have said they scoured the configs and haven't found anything specifying those headers except for AJAX requests.
#dont cache ajax requests
if(req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)")
Here's a curl from Pre-launch when we correctly configured Varnish to cache after forcing HTTPS(force-https plugin) on the site:
$ curl -Ik -H'X-Forwarded-Proto: *************
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Server: *****
Date: Sat, 03 Nov 2018 22:36:43 GMT
X-Varnish: 53061104
Age: 0
Via: 1.1 varnish
Connection: keep-alive
And from post launch:
curl -ILk ***********
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
X-Varnish: 691817320
Vary: Accept-Encoding
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type: text/html; charset=UTF-8
X-Server: ****
Date: Mon, 19 Nov 2018 19:17:02 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Transfer-Encoding: chunked
Accept-Ranges: bytes
Via: 1.1 varnish
Connection: Keep-Alive
Set-Cookie: X-Mapping-fjhppofk=33C486CB71216B67C5C5AB8F5E63769E; path=/
Age: 0
Force-https plugin: We activated this, updated the Varnish config to avoid a redirect loop and confirmed it was working a week prior to launch.
Plugins: These did not change, except for force-https.
Web App: It's an updated version of the previous app, complete redesign but nothing in the app from what I can tell is specifying no-store no-cache headers to be sent.
Where should I start? Thanks!
wordpress nginx varnish varnish-vcl timber
wordpress nginx varnish varnish-vcl timber
asked Nov 20 '18 at 16:31
Mk-EtlingerMk-Etlinger
6018
6018
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
What is sending these headers is PHP engine.
It does so whenever you initiate a session, which clearly happens based on Set-Cookie presence.
Make sure that PHP sessions are initiated only when absolutely needed. By default, Varnish will not cache when response includes either Set-Cookie or "negative" Cache-Control, you have both.
So getting rid of extraneous session_start() and/or setcookie() calls is the key here.
You can find more info on when you can expect anti-caching headers sent here.
Daniel, thanks so much for clarification on this. It has been driving me mad. Here's the only occurrence ofsession_start()orsession_set_cookie_params()setup.php: gist.github.com/Mk-Etlinger/845dbe94462f4701964e75d123098597 I don't consider this extraneous, but perhaps it's the culprit.
– Mk-Etlinger
Nov 20 '18 at 17:49
1
That on it's own is able to kill Varnish caching entirely, if this is used withinfunctions.phpor similar location which will execute on every page. You may want togrep -R X-Mapping .in your entire project directory, to find what is setting the specific cookie from your example curl output.
– Daniel V.
Nov 20 '18 at 17:52
Thanks Daniel! Nothing returns from greppingX-Mapping. When I comment out the above code in the gist, the headers are removed. Unfortunately, we need to use sessions in our app to manage social logins sitewide. Why is this the default behavior when using sessions? Is there a specific reason why you aren't supposed to cache if you're using cookies or sessions?
– Mk-Etlinger
Nov 20 '18 at 18:51
Here is what I'm currently reading to get caught up =) blog.fortrabbit.com/mastering-http-caching
– Mk-Etlinger
Nov 20 '18 at 19:18
1
If caching was allowed in presence of cookies, this may possibly result in one user seeing content designated for other users. Varnish does a sane default of bypassing cache/ing when cookies are set by backend or sent by a client. Things largely depend on the nature of a cookie. If this is for example a cookie for displaying your website in different languages, you can tell Varnish to cache in presence of cookies. But if that's a login cookie (PHP session), then you should let Varnish do the default.
– Daniel V.
Nov 20 '18 at 19:19
add a comment |
You need to fix the backend, but at the very least, you can strip the annoying header, and/or bypass it in varnish with this vcl snippet;
sub vcl_backend_response {
# kill the CC header so that application downstream don't see it
unset req.http.Cache-Control;
# alternatively, you can also override that header with
# set req.http.Cache-Control = "whatever string you desire";
# you can also force the TTL
beresp.ttl;
# also, if you return now, the builtin.vcl (https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl)
# doesn't get executed; this is generally the one deciding content is uncacheable
return (deliver);
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397435%2fvarnish-wordpress-nginx-prevent-no-store-no-cache-must-revalidate-headers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
What is sending these headers is PHP engine.
It does so whenever you initiate a session, which clearly happens based on Set-Cookie presence.
Make sure that PHP sessions are initiated only when absolutely needed. By default, Varnish will not cache when response includes either Set-Cookie or "negative" Cache-Control, you have both.
So getting rid of extraneous session_start() and/or setcookie() calls is the key here.
You can find more info on when you can expect anti-caching headers sent here.
Daniel, thanks so much for clarification on this. It has been driving me mad. Here's the only occurrence ofsession_start()orsession_set_cookie_params()setup.php: gist.github.com/Mk-Etlinger/845dbe94462f4701964e75d123098597 I don't consider this extraneous, but perhaps it's the culprit.
– Mk-Etlinger
Nov 20 '18 at 17:49
1
That on it's own is able to kill Varnish caching entirely, if this is used withinfunctions.phpor similar location which will execute on every page. You may want togrep -R X-Mapping .in your entire project directory, to find what is setting the specific cookie from your example curl output.
– Daniel V.
Nov 20 '18 at 17:52
Thanks Daniel! Nothing returns from greppingX-Mapping. When I comment out the above code in the gist, the headers are removed. Unfortunately, we need to use sessions in our app to manage social logins sitewide. Why is this the default behavior when using sessions? Is there a specific reason why you aren't supposed to cache if you're using cookies or sessions?
– Mk-Etlinger
Nov 20 '18 at 18:51
Here is what I'm currently reading to get caught up =) blog.fortrabbit.com/mastering-http-caching
– Mk-Etlinger
Nov 20 '18 at 19:18
1
If caching was allowed in presence of cookies, this may possibly result in one user seeing content designated for other users. Varnish does a sane default of bypassing cache/ing when cookies are set by backend or sent by a client. Things largely depend on the nature of a cookie. If this is for example a cookie for displaying your website in different languages, you can tell Varnish to cache in presence of cookies. But if that's a login cookie (PHP session), then you should let Varnish do the default.
– Daniel V.
Nov 20 '18 at 19:19
add a comment |
What is sending these headers is PHP engine.
It does so whenever you initiate a session, which clearly happens based on Set-Cookie presence.
Make sure that PHP sessions are initiated only when absolutely needed. By default, Varnish will not cache when response includes either Set-Cookie or "negative" Cache-Control, you have both.
So getting rid of extraneous session_start() and/or setcookie() calls is the key here.
You can find more info on when you can expect anti-caching headers sent here.
Daniel, thanks so much for clarification on this. It has been driving me mad. Here's the only occurrence ofsession_start()orsession_set_cookie_params()setup.php: gist.github.com/Mk-Etlinger/845dbe94462f4701964e75d123098597 I don't consider this extraneous, but perhaps it's the culprit.
– Mk-Etlinger
Nov 20 '18 at 17:49
1
That on it's own is able to kill Varnish caching entirely, if this is used withinfunctions.phpor similar location which will execute on every page. You may want togrep -R X-Mapping .in your entire project directory, to find what is setting the specific cookie from your example curl output.
– Daniel V.
Nov 20 '18 at 17:52
Thanks Daniel! Nothing returns from greppingX-Mapping. When I comment out the above code in the gist, the headers are removed. Unfortunately, we need to use sessions in our app to manage social logins sitewide. Why is this the default behavior when using sessions? Is there a specific reason why you aren't supposed to cache if you're using cookies or sessions?
– Mk-Etlinger
Nov 20 '18 at 18:51
Here is what I'm currently reading to get caught up =) blog.fortrabbit.com/mastering-http-caching
– Mk-Etlinger
Nov 20 '18 at 19:18
1
If caching was allowed in presence of cookies, this may possibly result in one user seeing content designated for other users. Varnish does a sane default of bypassing cache/ing when cookies are set by backend or sent by a client. Things largely depend on the nature of a cookie. If this is for example a cookie for displaying your website in different languages, you can tell Varnish to cache in presence of cookies. But if that's a login cookie (PHP session), then you should let Varnish do the default.
– Daniel V.
Nov 20 '18 at 19:19
add a comment |
What is sending these headers is PHP engine.
It does so whenever you initiate a session, which clearly happens based on Set-Cookie presence.
Make sure that PHP sessions are initiated only when absolutely needed. By default, Varnish will not cache when response includes either Set-Cookie or "negative" Cache-Control, you have both.
So getting rid of extraneous session_start() and/or setcookie() calls is the key here.
You can find more info on when you can expect anti-caching headers sent here.
What is sending these headers is PHP engine.
It does so whenever you initiate a session, which clearly happens based on Set-Cookie presence.
Make sure that PHP sessions are initiated only when absolutely needed. By default, Varnish will not cache when response includes either Set-Cookie or "negative" Cache-Control, you have both.
So getting rid of extraneous session_start() and/or setcookie() calls is the key here.
You can find more info on when you can expect anti-caching headers sent here.
answered Nov 20 '18 at 16:58
Daniel V.Daniel V.
1,97311314
1,97311314
Daniel, thanks so much for clarification on this. It has been driving me mad. Here's the only occurrence ofsession_start()orsession_set_cookie_params()setup.php: gist.github.com/Mk-Etlinger/845dbe94462f4701964e75d123098597 I don't consider this extraneous, but perhaps it's the culprit.
– Mk-Etlinger
Nov 20 '18 at 17:49
1
That on it's own is able to kill Varnish caching entirely, if this is used withinfunctions.phpor similar location which will execute on every page. You may want togrep -R X-Mapping .in your entire project directory, to find what is setting the specific cookie from your example curl output.
– Daniel V.
Nov 20 '18 at 17:52
Thanks Daniel! Nothing returns from greppingX-Mapping. When I comment out the above code in the gist, the headers are removed. Unfortunately, we need to use sessions in our app to manage social logins sitewide. Why is this the default behavior when using sessions? Is there a specific reason why you aren't supposed to cache if you're using cookies or sessions?
– Mk-Etlinger
Nov 20 '18 at 18:51
Here is what I'm currently reading to get caught up =) blog.fortrabbit.com/mastering-http-caching
– Mk-Etlinger
Nov 20 '18 at 19:18
1
If caching was allowed in presence of cookies, this may possibly result in one user seeing content designated for other users. Varnish does a sane default of bypassing cache/ing when cookies are set by backend or sent by a client. Things largely depend on the nature of a cookie. If this is for example a cookie for displaying your website in different languages, you can tell Varnish to cache in presence of cookies. But if that's a login cookie (PHP session), then you should let Varnish do the default.
– Daniel V.
Nov 20 '18 at 19:19
add a comment |
Daniel, thanks so much for clarification on this. It has been driving me mad. Here's the only occurrence ofsession_start()orsession_set_cookie_params()setup.php: gist.github.com/Mk-Etlinger/845dbe94462f4701964e75d123098597 I don't consider this extraneous, but perhaps it's the culprit.
– Mk-Etlinger
Nov 20 '18 at 17:49
1
That on it's own is able to kill Varnish caching entirely, if this is used withinfunctions.phpor similar location which will execute on every page. You may want togrep -R X-Mapping .in your entire project directory, to find what is setting the specific cookie from your example curl output.
– Daniel V.
Nov 20 '18 at 17:52
Thanks Daniel! Nothing returns from greppingX-Mapping. When I comment out the above code in the gist, the headers are removed. Unfortunately, we need to use sessions in our app to manage social logins sitewide. Why is this the default behavior when using sessions? Is there a specific reason why you aren't supposed to cache if you're using cookies or sessions?
– Mk-Etlinger
Nov 20 '18 at 18:51
Here is what I'm currently reading to get caught up =) blog.fortrabbit.com/mastering-http-caching
– Mk-Etlinger
Nov 20 '18 at 19:18
1
If caching was allowed in presence of cookies, this may possibly result in one user seeing content designated for other users. Varnish does a sane default of bypassing cache/ing when cookies are set by backend or sent by a client. Things largely depend on the nature of a cookie. If this is for example a cookie for displaying your website in different languages, you can tell Varnish to cache in presence of cookies. But if that's a login cookie (PHP session), then you should let Varnish do the default.
– Daniel V.
Nov 20 '18 at 19:19
Daniel, thanks so much for clarification on this. It has been driving me mad. Here's the only occurrence of
session_start() or session_set_cookie_params() setup.php: gist.github.com/Mk-Etlinger/845dbe94462f4701964e75d123098597 I don't consider this extraneous, but perhaps it's the culprit.– Mk-Etlinger
Nov 20 '18 at 17:49
Daniel, thanks so much for clarification on this. It has been driving me mad. Here's the only occurrence of
session_start() or session_set_cookie_params() setup.php: gist.github.com/Mk-Etlinger/845dbe94462f4701964e75d123098597 I don't consider this extraneous, but perhaps it's the culprit.– Mk-Etlinger
Nov 20 '18 at 17:49
1
1
That on it's own is able to kill Varnish caching entirely, if this is used within
functions.php or similar location which will execute on every page. You may want to grep -R X-Mapping . in your entire project directory, to find what is setting the specific cookie from your example curl output.– Daniel V.
Nov 20 '18 at 17:52
That on it's own is able to kill Varnish caching entirely, if this is used within
functions.php or similar location which will execute on every page. You may want to grep -R X-Mapping . in your entire project directory, to find what is setting the specific cookie from your example curl output.– Daniel V.
Nov 20 '18 at 17:52
Thanks Daniel! Nothing returns from grepping
X-Mapping. When I comment out the above code in the gist, the headers are removed. Unfortunately, we need to use sessions in our app to manage social logins sitewide. Why is this the default behavior when using sessions? Is there a specific reason why you aren't supposed to cache if you're using cookies or sessions?– Mk-Etlinger
Nov 20 '18 at 18:51
Thanks Daniel! Nothing returns from grepping
X-Mapping. When I comment out the above code in the gist, the headers are removed. Unfortunately, we need to use sessions in our app to manage social logins sitewide. Why is this the default behavior when using sessions? Is there a specific reason why you aren't supposed to cache if you're using cookies or sessions?– Mk-Etlinger
Nov 20 '18 at 18:51
Here is what I'm currently reading to get caught up =) blog.fortrabbit.com/mastering-http-caching
– Mk-Etlinger
Nov 20 '18 at 19:18
Here is what I'm currently reading to get caught up =) blog.fortrabbit.com/mastering-http-caching
– Mk-Etlinger
Nov 20 '18 at 19:18
1
1
If caching was allowed in presence of cookies, this may possibly result in one user seeing content designated for other users. Varnish does a sane default of bypassing cache/ing when cookies are set by backend or sent by a client. Things largely depend on the nature of a cookie. If this is for example a cookie for displaying your website in different languages, you can tell Varnish to cache in presence of cookies. But if that's a login cookie (PHP session), then you should let Varnish do the default.
– Daniel V.
Nov 20 '18 at 19:19
If caching was allowed in presence of cookies, this may possibly result in one user seeing content designated for other users. Varnish does a sane default of bypassing cache/ing when cookies are set by backend or sent by a client. Things largely depend on the nature of a cookie. If this is for example a cookie for displaying your website in different languages, you can tell Varnish to cache in presence of cookies. But if that's a login cookie (PHP session), then you should let Varnish do the default.
– Daniel V.
Nov 20 '18 at 19:19
add a comment |
You need to fix the backend, but at the very least, you can strip the annoying header, and/or bypass it in varnish with this vcl snippet;
sub vcl_backend_response {
# kill the CC header so that application downstream don't see it
unset req.http.Cache-Control;
# alternatively, you can also override that header with
# set req.http.Cache-Control = "whatever string you desire";
# you can also force the TTL
beresp.ttl;
# also, if you return now, the builtin.vcl (https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl)
# doesn't get executed; this is generally the one deciding content is uncacheable
return (deliver);
}
add a comment |
You need to fix the backend, but at the very least, you can strip the annoying header, and/or bypass it in varnish with this vcl snippet;
sub vcl_backend_response {
# kill the CC header so that application downstream don't see it
unset req.http.Cache-Control;
# alternatively, you can also override that header with
# set req.http.Cache-Control = "whatever string you desire";
# you can also force the TTL
beresp.ttl;
# also, if you return now, the builtin.vcl (https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl)
# doesn't get executed; this is generally the one deciding content is uncacheable
return (deliver);
}
add a comment |
You need to fix the backend, but at the very least, you can strip the annoying header, and/or bypass it in varnish with this vcl snippet;
sub vcl_backend_response {
# kill the CC header so that application downstream don't see it
unset req.http.Cache-Control;
# alternatively, you can also override that header with
# set req.http.Cache-Control = "whatever string you desire";
# you can also force the TTL
beresp.ttl;
# also, if you return now, the builtin.vcl (https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl)
# doesn't get executed; this is generally the one deciding content is uncacheable
return (deliver);
}
You need to fix the backend, but at the very least, you can strip the annoying header, and/or bypass it in varnish with this vcl snippet;
sub vcl_backend_response {
# kill the CC header so that application downstream don't see it
unset req.http.Cache-Control;
# alternatively, you can also override that header with
# set req.http.Cache-Control = "whatever string you desire";
# you can also force the TTL
beresp.ttl;
# also, if you return now, the builtin.vcl (https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl)
# doesn't get executed; this is generally the one deciding content is uncacheable
return (deliver);
}
answered Nov 22 '18 at 5:12
Guillaume QuintardGuillaume Quintard
1595
1595
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397435%2fvarnish-wordpress-nginx-prevent-no-store-no-cache-must-revalidate-headers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown