cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 CE + Varnish

0 Kudos

Magento2 CE + Varnish

Feature request from dzotic9, posted on GitHub Jun 16, 2016

Steps to reproduce

  1. Magento CE 2.0.7 + sample data
  2. App server nginx+php-fpm, Varnish for FPC default.vcl file - http://pastebin.ru/gsQnLUh0

Expected result

  1. Page should be cached with all resources

Actual result

  1. Cached only static resources, html not cached. Same requests (main page or same search requests) go to app server
2 Comments
apiuser
New Member

Comment from dzotic9, posted on GitHub Jun 16, 2016

main page response headers: HTTP/1.1 200 OK Server: openresty/1.9.7.1 Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Frame-Options: SAMEORIGIN Pragma: no-cache Expires: -1 Cache-Control: max-age=28800 Vary: Accept-Encoding Accept-Ranges: bytes

I am interesting in caching html pages also as static content. Thanks in advance

apiuser
New Member

Comment from allanpaiste, posted on GitHub Aug 25, 2016

I would guess that this might come from the web-server (we use Apache and Apache was the one who added the max-age=0 header for .html files) so try to either override the Cache-Control within .htaccess with ...

<ifModule mod_headers.c>
    <FilesMatch "\.(html|htm)$">
        Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
</ifModule mod_headers.c>

... or do it in .vcl ...

    # this should be added somewhere in vcl_backend_response ... for 
    # example after other url path extension checks. Do not nest it inside
    # some other if condition that checks for ttl, which for .html is 0.
    if (bereq.url ~ "^/pub/static/.*\.(html|htm)$") {
        set beresp.ttl = 2592000s;
        set beresp.http.Cache-Control = "max-age=2592000, public";
    }

We use the latter.

PS: remove the ^ if your local development environment base-url includes a project-name folder a'la my.local.dev/my-project/pub/static/...