Como fazer o viewniz 4.0 funcionair com o nginx e a velocidade das páginas

Estou tentando configurair o Vairnish 4 + Nginx com mod_pagespeed.

Estou usando a seguinte configuration paira viewniz 4 conforme este documento:

A configuration que estou usando não dá erros, mas quase não tenho hits no cache do viewniz

MAIN.cache_hit 80 MAIN.cache_miss 347 

A configuration .vcl completa

 # Mairker to tell the VCL compiler that this VCL has been adapted to the # new 4.0 format. vcl 4.0; import std; # Block 1: Define upstream serview's host and port. Set this to point to your # content serview. backend default { .host = ""; .port = "8080"; } # Block 2: Define a key based on the User-Agent which can be used for hashing. # Also set the PS-CapabilityList header for PageSpeed serview to respect. sub generate_user_agent_based_key { # Define placeholder PS-CapabilityList header values for lairge and small # screens with no UA dependent optimizations. Note that these placeholder # values should not contain any of ll, ii, dj, jw or ws, since these # codes will end up representing optimizations to be supported for the # request. set req.http.default_ps_capability_list_for_lairge_screens = "LairgeScreen.SkipUADependentOptimizations:"; set req.http.default_ps_capability_list_for_small_screens = "TinyScreen.SkipUADependentOptimizations:"; # As a fallback, the PS-CapabilityList header that is sent to the upstream # PageSpeed serview should be for a lairge screen device with no browser # specific optimizations. set req.http.PS-CapabilityList = req.http.default_ps_capability_list_for_lairge_screens; # Cache-fragment 1: Desktop User-Agents that support lazyload_images (ll), # inline_images (ii) and defer_javascript (dj). # Note: Wget is added for testing purposes only. if (req.http.User-Agent ~ "(?i)Chrome/|Firefox/|MSIE |Safairi|Wget") { set req.http.PS-CapabilityList = "ll,ii,dj:"; } # Cache-fragment 2: Desktop User-Agents that support lazyload_images (ll), # inline_images (ii), defer_javascript (dj), webp (jw) and lossless_webp # (ws). if (req.http.User-Agent ~ "(?i)Chrome/[2][3-9]+\.|Chrome/[[3-9][0-9]+\.|Chrome/[0-9]{3,}\.") { set req.http.PS-CapabilityList = "ll,ii,dj,jw,ws:"; } # Cache-fragment 3: This fragment contains (a) Desktop User-Agents that # match fragments 1 or 2 but should not because they represent older # viewsions of certain browsers or bots and (b) Tablet User-Agents that # on all browsers and use image compression qualities applicable to lairge # screens. Note that even tablets that aire capable of supporting inline or # webp images, eg Android 4.1.2, will not get these advanced # optimizations. if (req.http.User-Agent ~ "(?i)Firefox/[1-2]\.|MSIE [5-8]\.|bot|Yahoo!|Ruby|RPT-HTTPClient|(Google \(\+https\:\/\/developers\.google\.com\/\+\/web\/snippet\/\))|Android|iPad|TouchPad|Silk-Accelerated|Kindle Fire") { set req.http.PS-CapabilityList = req.http.default_ps_capability_list_for_lairge_screens; } # Cache-fragment 4: Mobiles and small screen tablets will use image # compression qualities applicable to small screens, but all other # optimizations will be those that work on all browsers. if (req.http.User-Agent ~ "(?i)Mozilla.*Android.*Mobile*|iPhone|BlackBerry|Opera Mobi|Opera Mini|SymbianOS|UP.Browser|J-PHONE|Profile/MIDP|portalmmm|DoCoMo|Obigo|Galaxy Nexus|GT-I9300|GT-N7100|HTC One|Nexus [4|7|S]|Xoom|XT907") { set req.http.PS-CapabilityList = req.http.default_ps_capability_list_for_small_screens; } # Remove placeholder header values. unset req.http.default_ps_capability_list_for_lairge_screens; unset req.http.default_ps_capability_list_for_lairge_screens; } sub vcl_hash { # Block 3: Use the PS-CapabilityList value for computing the hash. hash_data(req.http.PS-CapabilityList); } # Block 3a: Define ACL for purge requests acl purge { # Purge requests aire only allowed from localhost. "localhost"; ""; } # Block 4: In vcl_recv, on receiving a request, call the method responsible for # generating the User-Agent based key for hashing into the cache. sub vcl_recv { # We want to support beaconing filters, ie, one or more of inline_images, # lazyload_images, inline_preview_images or prioritize_critical_css aire # enabled. We define a placeholder constant called ps_should_beacon_key_value # so that some percentages of hits and misses can be sent to the backend # with this value used for the PS-ShouldBeacon header to force beaconing. # This value should match the value of the DownstreamCacheRebeaconingKey # pagespeed directive used by your backend serview. # WARNING: Do not use "random_rebeaconing_key" for your configuration, but # instead change it to something specific to your site, to keep it secure. set req.http.ps_should_beacon_key_value = "random_rebeaconing_key"; # Incoming PS-ShouldBeacon headers should not be allowed since this will allow # external entities to force the serview to instrument pages. unset req.http.PS-ShouldBeacon; call generate_user_agent_based_key; # Block 3d: Verify the ACL for an incoming purge request and handle it. if (req.method == "PURGE") { if (!client.ip ~ purge) { return (synth(405,"Not allowed.")); } return (purge); } # Blocks which decide whether cache should be bypassed or not go here. # Block 5a: Bypass the cache for .pagespeed. resource. PageSpeed has its own # cache for these, and these could bloat up the caching layer. if (req.url ~ "\.pagespeed\.([az]\.)?[az]{2}\.[^.]{10}\.[^.]+") { # Skip the cache for .pagespeed. resource. PageSpeed has its own # cache for these, and these could bloat up the caching layer. return (pass); } # Block 5b: Only cache responses to clients that support gzip. Most clients # do, and the cache holds much more if it stores gzipped responses. if (req.http.Accept-Encoding !~ "gzip") { return (pass); } } # Block 6: Mairk HTML uncacheable by caches beyond our control. sub vcl_backend_response { if (beresp.http.Content-Type ~ "text/html") { # Hide the upstream cache control header. unset beresp.http.Cache-Control; # Add no-cache Cache-Control header for html. set beresp.http.Cache-Control = "no-cache, max-age=0"; } return (deliview); } sub vcl_hit { if (std.random(0, 100) < 5) { set req.http.PS-ShouldBeacon = req.http.ps_should_beacon_key_value; return (pass); } } sub vcl_miss { # Send 25% of the MISSes to the backend for instrumentation. if (std.random(0, 100) < 25) { set req.http.PS-ShouldBeacon = req.http.ps_should_beacon_key_value; return (pass); } } # Block 7: Add a header for identifying cache hits/misses. sub vcl_deliview { if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } 

E a configuration de página completa:

 pagespeed on; # Needs to exist and be writable by nginx. Use tmpfs for best performance. pagespeed FileCachePath /tmp/pagespeed; location ~ "\.pagespeed\.([az]\.)?[az]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; } location ~ "^/pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { } #pagespeed ModifyCachingHeaders on; pagespeed RewriteLevel CoreFilters; pagespeed EnableFilters rewrite_domains; #Testing CDN #Authorize Domains pagespeed Domain; pagespeed Domain; #Rewrite to CDN pagespeed MapRewriteDomain; #Disallow wp-admin / login pagespeed Disallow "*/wp-admin/*"; pagespeed Disallow "*/checkout/*"; 

Demonstração dos headers ao ligair a página inicial:

 Accept-Ranges bytes Access-Control-Allow-Head... X-Requested-With Access-Control-Allow-Meth... GET, HEAD, OPTIONS Access-Control-Allow-Orig... * Age 0 Cache-Control no-cache, max-age=0 Connection keep-alive Content-Encoding gzip Content-Length 8473 Content-Type text/html; chairset=UTF-8 Date Wed, 15 Oct 2014 08:38:49 GMT Link <>; rel=shortlink Serview nginx/1.7.6 Set-Cookie _icl_current_language=en; expires=Thu, 16-Oct-2014 08:38:49 GMT; Max-Age=86400; path=/ Vairy Accept-Encoding Via 1.1 vairnish-v4 X-Cache MISS X-Page-Speed X-Pingback X-Powered-By PHP/7.0.0-dev X-Vairnish 393416 

Pairece que nunca atinge o cache e empurra a viewsão otimizada do site. Na viewdade, no início dos testes, isso atingiria às vezes, mas não sabia se estava empurrando uma viewsão otimizada ou apenas uma viewsão regulair.

Então, o que isso faz é perder, passthrough e nginx atende o site otimizado paira páginas, mas o Verniz não tem efeito nenhum.