Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Varnish won't work because cache-control is being sent as nocache #275

Open
MaffooBristol opened this issue Jul 7, 2017 · 12 comments
Open

Comments

@MaffooBristol
Copy link

I may be missing something, but the config seems to force main pages on Drupal to send a Cache-Control: nocache header, which stops Varnish from doing its thang. I am aware that microcaching is used, but should it not also respect the drupal cache settings?

Thanks

@guiajlopes
Copy link

where are you seeing the nocache header? I use this setup with varnish and it works really well

@MaffooBristol
Copy link
Author

image

@guiajlopes
Copy link

guiajlopes commented Jul 27, 2017

I mean where are you seeing the header no-cache being set on nginx config?

@MaffooBristol
Copy link
Author

I'm not sure, I'm using this config mostly out of the box, but I have no idea what the cause/origin is!

@guiajlopes
Copy link

guiajlopes commented Jul 27, 2017

Probably not, I search on the repo for no-cache and haven't found. I saw that you have cookie on your request, is it the session? If so keep in mind that the drupal page cache doesn't work for logged in users and drupal always send no-cache in this case. If you are testing as anonymous user and still having the problem with no-cache there it's being set in another place.

@MaffooBristol
Copy link
Author

Hmm, it is odd. And no, it's the same for anonymous users. I guess it's somewhere else but I'm not sure where, perhaps it's just my Varnish config that's screwed, even though I used (again) an out-of-the box example from, I think d.org

@guiajlopes
Copy link

The no-cache for anonymous make totally sense since the website have different behaviours per user.

Probably it's something on your varnish config, or also in the drupal cache configuration. Take a look into this varnish vcl file, it should work fine. https://github.com/Lullabot/varnish

@MaffooBristol
Copy link
Author

Thanks. I actually turned Varnish off completely and am still getting no-cache coming up. I also have this constant bug with microcaching being used when logged in, and on admin pages, so that the admin pages get stuck in a loop (for example, running cron does nothing first time, takes about 5 attempts... or saving a page will show the drupal_set_message for seconds before it disappears again)

@MaffooBristol
Copy link
Author

I just created a completely blank, vanilla D7 site. Turned off all Varnish and Redis and the like, and the headers still come back with cache-control: no-cache. I have no more ideas!

$ curl -I mysite

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 30 Jul 2017 16:22:03 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Keep-Alive: timeout=10
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Etag: "1501431723-0"
Content-Language: en
X-Frame-Options: SAMEORIGIN
Cache-Control: no-cache
Last-Modified: Sun, 30 Jul 2017 16:22:03 GMT
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Vary: Cookie
Vary: Accept-Encoding
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
X-Content-Options: nosniff

@MaffooBristol
Copy link
Author

Okay, small update, I found what was doing it.

If you look in /etc/nginx/apps/drupal/microcache_fcgi.conf, there are these lines:

## Bypass the cache.
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;

## To avoid any interaction with the cache control headers we expire
## everything on this location immediately.
expires epoch;

... so as stated, it seems to be using microcaching. But why? It completely overwrites the caching settings in Drupal, which I think is really bad. Especially if it's not made obvious where this is coming from or how it's working! Uncommenting those lines has made http://www.isvarnishworking.com/ go from "sort of" to "yes", due to now having an age > 0

So, this thread is maybe more of a discussion? Is this the right behaviour?

@MaffooBristol
Copy link
Author

There's also still the weird bug with caching on admin pages. Now, the headers coming from Drupal are working perfectly Age:0 and Cache-Control:no-cache, must-revalidate, however I'm getting X-Micro-Cache:HIT. This microcache should definitely not be working on admin pages, so I'm assuming I'll have to entirely comment that out too

@guiajlopes
Copy link

guiajlopes commented Aug 1, 2017

doesn't make sense have Microcaching if you have a varnish in front of it. I think the config of microcaching make sense only when you don't have an http cache layer...

In my infra I don't use microcaching, just a reverse proxy and drupal cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants