How do I configure Varnish so that all responses to requests matching say "*.css" gets cached in the client's browser for 30 days?
What I'm trying to achieve is making Varnish set the correct "Expires:" and/or "Cache-Control" settings so that all CSS:s are cached for 30 days regardless of what the backend says about the client-side cacheability of these objects.
This does the trick:
I don't think that Varnish will let you scope the VCL rules to "*.css". You may have to ask on the Varnish mailing list for exact info on this. Scoping by MIME type should be possible.
Assuming your objects already have cache headers set but you wish to normalize them, then a modified version of this Varnish documentation VCL should help you: http://varnish.projects.linpro.no/wiki/VCLExampleLongerCaching
In general, Varnish was not built to do larger amounts of header or content rewriting. Your web servers or web application should do this better than Varnish.
I just need to point out that varnish is actually excellent for rewriting headers. Testing for any url is possible in vcl_recv, and in vcl_fetch, it is a common application for varnish. In recv, you analyze an incoming request. In fetch you analyze the backend response.
Generally, you manipulate the request in recv, and direct it to a backend, and you manipulate the response in fetch, and rewrite headers to suit, before storing the object in the cache potentially, and delivering the response.
In fetch you can do
as well as
and so on.