How to set page cache expires to 7 days?

Posted January 5, 2020 5.6k views

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

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.

Submit an Answer
1 answer

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.