Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a custom tool which generates a part of nginx config in the following form, for example:

upstream  backend  {
  ip_hash;
  server server1:8080;
  server server2:8080;
  server localhost:8080 backup;
 }

From time to time some servers go down, some go up and the next update could produce following:

upstream  backend  {
  ip_hash;
  server server1:8080;
  server server3:8080;
  server server2:8080 down;
  server localhost:8080 backup;
 }

As you can see, server3 has appeared and server2 is marked down. My question is following: does nginx care the order of servers presented in config? Do I need to sort output of my custom tool?

In this example the initial order was changed and I don't know if nginx will handle it correctly.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

IIRC, w/ the ip_hash rotation method, order does matter. Nginx hashes the client ip, then sends clients to one of the items in the list. If you change the order, ip_hash will direct clients to another upstream node. Per the recommendation here, I'd leave the entire list of servers in your file all the time, and simply mark it 'down' if it's offline.

share|improve this answer
    
Sure, that's what my tool does, but it stores the list of servers in memory and rewrites the file each time, writing up servers first, down servers next. I will change this, thank you. –  Shaman Jul 30 '10 at 7:54

Your Answer

 
discard

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.