Question

How to set page cache expires to 7 days?

I am using varnish with default magento 2.3.3 VCL and the default nginx configuration that comes with magento install. At present I see the expires is set to -1. How can I set expires to one week?

status: 200
content-length: 22478
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-encoding: gzip
accept-ranges: bytes
access-control-expose-headers: Content-Length, Content-Range
vary: Accept-Encoding
expires: -1
server: nginx
strict-transport-security: max-age=31536000
pragma: no-cache
cache-control: no-store, no-cache, must-revalidate, max-age=0
date: Mon, 04 Jan 2020 15:04:45 GMT
x-frame-options: SAMEORIGIN
access-control-allow-headers: DNT,User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range
content-type: text/html; charset=UTF-8
access-control-allow-origin: *
access-control-allow-methods: GET, POST, OPTIONS
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @riyaaaz,

In order to set the expires time for your cache, you’ll need to add it to your location block where caching has been allowed.

It will look something like this

location ~* \.(?:*)$ {
    expires 2d;
    add_header Pragma public;
    add_header Cache-Control "public"
}

See the expires 2d. That means that every cache will expire after 2 days.

Regards, KDSys