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 -

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
New Member

Comment from dzotic9, posted on GitHub Jun 16, 2016

main page response headers: HTTP/1.1 200 OK Server: openresty/ 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

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"
</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