0

I've got 2 servers load balanced with ELB. Each server has a copy of the same rails app, with nginx in front and unicorn as the appserver.

There is no css file that is loading in a browser window now. When inspect Element, i see that it's looking for say application-123123.css which is on the OTHER server.

So it appears that the browser gets server 1, loads up it's html which has application-123123123.css precompiled on it. then when the actual call to load application-123123123.css gets sent it goes to SERVER 2 which has it's own timestamp (for lack of better word) and errors because the file for application-123123123.css doesn't exist.

I'm at a loss for Duck duck go fodder and what to look for in nginx/appserver settings. Thoughts?

pjammer
  • 194
  • 1
  • 5

1 Answers1

0

There's 2 ways you can go about fixing this. The first is to make your application behave so that, regardless of which server the request hits, it knows what's being asked of it. This is the preferred, and most robust solution, but is heavily dependent on your application and how it collects its static files into a place that nginx can see, and do so in a way that's consistent across runs. I'm no rails developer, so can't speak for what you need to do to make this load balance correctly. A common way to deal with cache busting isn't to use the timestamp the file was generated, but rather some sort of hash of the contents of the file itself. If the file doesn't change, the hash won't change, and the hash will be generated consistently across servers, regardless of whether the file changed or not.

The second is to enable "sticky sessions" on your load balancer, which will keep the user pointed at the same server for as long as the sticky cookie remains in their browser, or expires. The dangers behind doing this though, is that if the server they're "stuck" to goes away (due to a manual or time/load based tear down), then the user may experience some issues if the servers are behaving slightly differently to one another. You'll need to examine your application in more detail to fully understand what, if anything, will be impacted here.

dannosaur
  • 953
  • 5
  • 15