Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently I am setting up HA proxy to route requests to my application servers.

My application servers will be running nginx with phusion passenger.

From what I understand, varnish only caches pages w/o cookies. How would this work on a dynamic website?

Say like serverfault, where you have logged in users and anonymous users. Pages may be updated by voting/comments/answers/editing etc.

How would varnish fit into the picture?

I understand the basic idea that varnish is at the top of the stack, so even if you are using memcached that will hit the web server and be "slower" than a pure cache hit at the top of the stack with varnish.

share|improve this question

From what I understand, varnish only caches pages w/o cookies

No, this is incorrect. It works in concert with the application to provide a caching layer. Varnish will usually be used to cache any static content, as well as content that is less frequently changed. The backend application can control how things are cached by using Cache-Control headers.

Start here to get an idea of the architecture, and what Varnish can do:

share|improve this answer
so at a basic level, if I wanted to cache all anonymous users, what would I do? (as oppose to those logged in) – Blankman Jun 7 '11 at 21:36
@Blankman - If you can differentiate anon users by their request, possibly with a cookie, or absence thereof, you can configure varnish to cache only those results. In the end though, your application has the most knowledge of what is cacheable, and having the application output the correct cache control headers gives you the most control. – JimB Jun 8 '11 at 2:07

Varnish can be used to stack any and all static assets such as images, css, and javascript. While the text content of your page might change, those assets do not. You can therefore (theoretically) save a bundle by caching them upfront.

share|improve this answer

One of the things we've done in our shop is to allow web devs the ability to poke the varnish server and automatically expire cached resources. Specifically, whenever content's updated, that URL or what have you is automatically evicted from the varnish cache. It's not a silver bullet, but it's definitely been worthwhile in a few places.

share|improve this answer

You can use varnish as a load balancer too so you can probably replace HAProxy with varnish and get both load balancing and cache.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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