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

Not able to work varnish-4.0 template with Drupal #29

Closed
jgardezi opened this issue Jul 8, 2016 · 13 comments
Closed

Not able to work varnish-4.0 template with Drupal #29

jgardezi opened this issue Jul 8, 2016 · 13 comments

Comments

@jgardezi
Copy link

jgardezi commented Jul 8, 2016

Hi @mattiasgeniar,

I have tried to use default.vlc template in varnish-4.0-configuration-templates. It seem like it is not working. Is their any configuration I need to do in the template in order to make it work. Please let me know?

My drupal 7 setting are
$conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc'; $conf['cache_class_external_varnish_page'] = 'VarnishCache'; $conf['reverse_proxy'] = true; $conf['reverse_proxy_addresses'] = array('172.31.10.68'); $conf['reverse_proxy_header'] = 'HTTP_X_FORWARDED_FOR'; $conf['cache_lifetime'] = 0; $conf['page_cache_maximum_age'] = 21600; $conf['page_cache_invoke_hooks'] = false;

The reply I got from curl -I http://stage.mysite.com/ is
HTTP/1.1 200 OK Date: Fri, 08 Jul 2016 05:27:39 GMT X-Content-Type-Options: nosniff Cache-Control: max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0 X-Content-Type-Options: nosniff Content-Language: en X-UA-Compatible: IE=edge Vary: Accept-Encoding X-Mod-Pagespeed: 1.9.32.14-0 Content-Type: text/html; charset=utf-8 Age: 0 X-Cache: MISS X-Cache-Hits: 0 Connection: keep-alive

When I used configuration from NITEMAN. It works but issue is that its not setting max-age properly

HTTP/1.1 200 OK Date: Fri, 08 Jul 2016 05:06:32 GMT Server: Apache X-Content-Type-Options: nosniff Cache-Control: max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0 X-Content-Type-Options: nosniff Content-Language: en X-UA-Compatible: IE=edge X-Generator: Drupal 7 (http://drupal.org) Link: <http://stage.mysite.com/>; rel="canonical",<http://stage.mysite.com/>; rel="shortlink" Vary: Accept-Encoding X-Mod-Pagespeed: 1.9.32.14-0 Content-Type: text/html; charset=utf-8 X-Varnish-Cacheable: NO:Not Cacheable X-Varnish: 163872 Age: 0 Via: 1.1 varnish-v4 X-Varnish-Cache: MISS X-Varnish-Server: varnish Connection: keep-alive

Please help me I am new to this.

Kind regards,
Javed Gardezi

@mattiasgeniar
Copy link
Owner

Hi!

The first thing you're going to have to change is Drupal's "cache anonymous pages" setting, because all your replies are still setting this header:

Cache-Control: max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0

The "no-cache" is something Varnish listens to, so it won't cache the page. That needs to be a public cache header.

@jgardezi
Copy link
Author

jgardezi commented Jul 8, 2016

@mattiasgeniar Thank you for the reply.

I have checked the box "cache anonymous pages". Now my headers changed to the following

Cache-Control: max-age=0, no-cache

Details.

HTTP/1.1 200 OK Date: Fri, 08 Jul 2016 07:20:05 GMT X-Content-Type-Options: nosniff Cache-Control: max-age=0, no-cache X-Content-Type-Options: nosniff Content-Language: en X-UA-Compatible: IE=edge Vary: Cookie,Accept-Encoding X-Mod-Pagespeed: 1.9.32.14-0 Content-Type: text/html; charset=utf-8 Age: 0 X-Cache: MISS X-Cache-Hits: 0 Connection: keep-alive

Still did not get varnish though.

@mattiasgeniar
Copy link
Owner

There's still something wrong with your headers in response:

Cache-Control: max-age=0, no-cache

Have you set a TTL for those cacheable pages?

@jgardezi
Copy link
Author

jgardezi commented Jul 8, 2016

Yes i set Expiration of cached pages to 6 hrs. My varnish and apache servers are on seperate VMs.

@jgardezi
Copy link
Author

jgardezi commented Jul 8, 2016

Let me check that i am not having issues with other modules. I have found this post http://www.mediacurrent.com/blog/why-isnt-my-page-caching and will get back to you accordingly.

@jgardezi
Copy link
Author

jgardezi commented Jul 11, 2016

Hi @mattiasgeniar

I have looked at the link and it seem like things are ok. Drupal cache headers issue.

I am having issues with headers Cache-Control: max-age=0, no-cache. Drupal 7 is unable set the proper headers. I have tried every thing still no luck.

Warm regards,
Javed Gardezi

@mattiasgeniar
Copy link
Owner

Hi,

Without access to your drupal and/or server, there isn't much I can do. It's a drupal issue here where it's sending the wrong headers, has nothing to do with this VCL.

Maybe your hosting provider can help?

Mattias

@jgardezi
Copy link
Author

Thank you @mattiasgeniar for replying.

There are some Drupal modules that are setting the headers to Cache-Control: max-age=0, no-cache. I have tried different type of configurations and still the headers were wrong.

I am in a process of figuring out which Drupal modules are causing it. I have to explicitly search the string no-cache in my modules directory to see what's going on.

Warm regards,
Javed Gardezi

@jgardezi
Copy link
Author

jgardezi commented Jul 13, 2016

Hi @manarth

Ok I was able to fix apache server to send the following headers from Drupal

From Mac Terminal

curl -I http://mysite.com/
HTTP/1.1 200 OK
Date: Wed, 13 Jul 2016 07:16:13 GMT
Server: Apache
X-Content-Type-Options: nosniff
X-Drupal-Cache: HIT
Etag: "1468393490-0"
X-Content-Type-Options: nosniff
X-Frame-Options: SameOrigin
Content-Language: en
X-UA-Compatible: IE=edge
X-Generator: Drupal 7 (http://drupal.org)
Link: <http://mysite.com/>; rel="canonical",<http://mysite.com/>; rel="shortlink"
Cache-Control: public, max-age=21600
Last-Modified: Wed, 13 Jul 2016 07:04:50 GMT
Expires: Sun, 19 Nov 1978 05:00:00 GMT
X-XSS-Protection: 1; mode=block
Content-Type: text/html; charset=utf-8

As you can see Cache-Control: public, max-age=21600 is sending properly. But when I use varnish I am getting the following headers. I am using this varnish vcl https://github.com/mattiasgeniar/varnish-4.0-configuration-templates/blob/master/default.vcl.

HTTP/1.1 200 OK
Date: Wed, 13 Jul 2016 07:25:33 GMT
Accept-Ranges: bytes
Vary: Accept-Encoding
X-Mod-Pagespeed: 1.9.32.14-0
Cache-Control: max-age=0, no-cache
Content-Type: text/html
Age: 0
X-Cache: MISS
X-Cache-Hits: 0
Connection: keep-alive

Please let me know what I need to change in my vcl file. I cannot see any varnish headers.

Warm regards,
Javed Gardezi

@mattiasgeniar
Copy link
Owner

How certain are you that Varnish is pointing to the same webserver?

Your original request, the one going directly to Apache, does not have the X-Mod-Pagespeed header, which the Varnish request does.

This could mean it isn't the same webserver that's responding?

@ayberkkimsesiz
Copy link

ayberkkimsesiz commented Aug 5, 2016

Hi @mattiasgeniar

Is it also possible to add a setting to this file for XenForo forum (domain.com/forum)?

Thanks.

@rafaelmagic
Copy link

X-Mod-PageSpeed means that your server is using Google PageSpeed Module.

GPS Module sets the header to not cache HTML files.

You have two choices:

  1. Use GPS downstream cache tutorial

  2. Set a GPS beacon to load fully optimized HTML and then use varnish to unset the GPS headers and set correct headers that are Varnish friendly.

@rafaelmagic
Copy link

Or email me and I can send you Part 2

Mattias close the issue and thank you for your vlc.

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

4 participants