Does anyone know a way to add expires header to a response in Varnish, like Apache does? Using Apache directives you can set expire headers and set how much time from now they will expire i.e. 1 month 15 days 2 hours, like this:

ExpiresByType text/html "access plus 1 month 15 days 2 hours"
ExpiresByType image/gif "modification plus 5 hours 3 minutes" 
link|improve this question
feedback

1 Answer

You can not do that with Varnish. You can define an "Expires" header like set beresp.http.Expires = XXXX in vcl_fetch. But you can not base the value of your header on an mtime/atime because Varnish never touches files sent by Apache and so can not get access to you mtime/atime.

You could actually send two extra headers from your origin server to inform Varnish about the resource's mtime/atime, something like X-Mtime: 1234 an X-Atime: 1234 so you can fetch them from Varnish with beresp.http.X-Mtime or beresp.http.X-Atime but this looks really overkill to me.

Furthermore you would need Apache/Nginx to send those custom headers for each request and to be honnest I do not know if that is possible to get such informations.

'hope that helps :)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.