Why cache static files with Varnish, why not pass
Posted
by
Saif Bechan
on Server Fault
See other posts from Server Fault
or by Saif Bechan
Published on 2011-12-20T01:01:25Z
Indexed on
2012/09/02
15:40 UTC
Read the original article
Hit count: 281
I have a system runnning nginx / php-fpm / varnish / wordpress and amazon s3.
Now I have looked at a lot of configuration files while setting up the system, and in all of them I found something like this:
/* If the request is for pictures, javascript, css, etc */
if (req.url ~ "\.(jpg|jpeg|png|gif|css|js)$") {
/* Remove the cookie and make the request static */
unset req.http.cookie;
return (lookup);
}
I do not understand why this is done. Most of the examples also run NginX as a webserver. Now the question is, why would you use the varnish cache to cache these static files.
It makes much more sense to me to only cache the dynamic files so that php-fpm / mysql don't get hit that much.
Am I correct or am I missing something here?
UPDATE
I want to add some info to the question based on the answer given.
If you have a dynamic website, where the content actually changes a lot, chaching does not make sense. But if you use WordPress for a static website for example, this can be cached for long periods of time.
That said, more important to me is static conent. I have found a link with some test and benchmarks on different cache apps and webserver apps.
http://nbonvin.wordpress.com/2011/03/14/apache-vs-nginx-vs-varnish-vs-gwan/
NginX is actually faster in getting your static content, so it makes more sense to just let it pass. NginX works great with static files.
--
Apart from that, most of the time static content is not even in the webserver itself. Most of the time this content is stores on a CDN somewhere, maybe AWS S3, something like that. I think the varnish cache is the last place where you want to have you static content stored.
© Server Fault or respective owner