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.

Is the Nginx's load balancing policy customizable in any way? Having two sites A and B I want 20% of all the requests to go to A and the rest to B. Is that possible/feasible? Is there a better solution out there for this task?

Thanks,

Alex

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

In your upstream block you can adjust the weights like this:

upstream upstream_server {
            server 192.168.1.11:80 weight=2;
            server 192.168.1.12:80 weight=8;
}

For every 10 requests, it will send 2 to 1.11, and 8 to 1.12, about an 20%/80% divide.

There are a bunch of options like to set an idle spare, and load balancing by source IP address. See the docs for more details about the upstream parameter.

share|improve this answer
    
Thanks :). I'll look at the docs. –  Alex Mar 22 '10 at 13:10
    
Is this on the same physical machine or two separate. If this is on one machine does this matter, because i assume that there is only one instance of nginx running. –  Saif Bechan Apr 2 '10 at 10:40
    
In our setup (+ and what I'm recommending here), .11 & .12 would be 2 separate machines. For us, nginx uses so little CPU, usually one of the machines in our upstream cluster is the nginx front-end itself. (backends are on ports other than :80) But I could conceivably see a scenario where you cannot tolerate any downtime, and can reload code by restarting the server on alternating ports on the same machine. –  Jason Apr 2 '10 at 12:20
add comment

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.