I have this weird issue and I'm not sure if it's me who's doing something wrong or I'm just missing something but maybe some of you can guide me a little bit here...

i setup a varnish server, within varnish itself i created 2 backends and using director i'm able to do round robin to my webheads. That parts seems to be working fine as I'm able to bring one of my webheads down and the other one can serve content to varnish and vice verse.

but here is a kicker... i noticed that sometimes page doesn't load properly so i start looking into why and I noticed some of the files are 304 or 404, so turns out somehow some of files in (files/css/.css or files/js/.js are missing), so I rsync them so now they all appears to have same content in those directories, but when i go to another page it seems like drupal generates more of those and since varnish goes to a round robin for any hit it serves some of page from one webhead and another part from another, so even though css,js file has been generated on first webhead it not generated on second and hence shows 304 or 404.

please advise


2 Answers 2


This is happening when you have optimization for CSS/JS turned on. These files are generated regarding the context (the page visited by the browser) and so the visitor won't be served some files when the round robin changed the targeted server.

You can configure the round robin to stay on the same server on a per-session basis (see: Pure VCL cookie-based sticky sessions in Varnish 2.1), but generally you should set up a NFS share between your server where you'll put the sites/default/files folder.

Source: Drupal's optimize CSS and JavaScript setting causing problems in multiple server environments.

  • I'm thinking about NFS share as one option, but how can I make Varnish's RR to stay on same server on per-session basis?
    – alexus
    Commented Dec 20, 2011 at 20:31
  • I'm not extremely familiar with varnish configuration, but in RR this is called sticky session (or sometime session affinity). I updated my post to give you a tutorial about it.
    – tostinni
    Commented Dec 20, 2011 at 20:50

The session thing is called "Sticky session", here is the first result when googling for "varnish sticky session": http://monolight.cc/2011/01/pure-vcl-cookie-based-sticky-sessions-in-varnish-2-1/.

However, this doesn't help, if have multiple web servers, you need to share the files directory between them. Not just for css/js aggregration, but also uploaded files and so on. NFS is one option, but you need to keep in mind that you introduce a new single point of failure which you need to make redundant again, if you need high availability.

Pantheon, a high performance hosting platform for Drupal, recently published an interesting article on how they invented a completely new file system to share the files directory between multiple web servers where they also outline the advantages and disadvantages of the existing solutions: https://getpantheon.com/news/inside-pantheon-valhalla-filesystem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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