2

I'm setting up an Nginx web server and and want to perform load balancing using the round robin method. This is what I have found thus far:

upstream backend  {
   server backend1.example.com;
   server backend2.example.com;
   server backend3.example.com;
}

According to the page they says i need to add the above lines to my nginx.conf file and upload it to server to load balance. I do not understand what it means by server backend3.example.com;. How do I setup a backend instance?

4

Those are the backend servers that will handle the incoming request.

So your domain's DNS should point to this nginx server, which will then use your upstream configuration to pass the request to one of the specified servers.

Your config should look something like this (inside http {} block)...

upstream backend  {
  server backend1.example.com;
  server backend2.example.com;
  server backend3.example.com;
}

server {
  location / {
    proxy_pass http://backend;
  }
}

Some notes...

  • You can use the load balancer as another 'backend' if you want to.
  • If you need https, then simply change proxy_pass http://backend; to proxy_pass https://backend; but make sure your backend servers are prepared to handle https.
  • If your backend service uses sessions (such as PHP sessions), then you will need to setup some kind of session persistence, but that is unrelated.

You can find much more information for advanced configuration in the docs of nginx.

| improve this answer | |
  • 1
    @AvinashBabu Load balancing can be quite an advanced setup. If you are not familiar / confident with it yet then I would suggest you do some research on the concept first. Once you've got more understanding and have attempted to set it up (use a tutorial) then you can ask for help if you run into any issues. – Clarkey May 1 '14 at 14:32
  • 1
    A backend server is just another instance/server running nginx. For example in AWS it would be another compute node. You have the front end nginx server accept the request and it then proxy passes the request in a round robin algorithm to one of the servers in the list. – jmq May 1 '14 at 14:34
  • 1
    @AvinashBabu You need additional machines that are setup with a web server which are serving the same content to test load balancing with. You can't load balance nothing. – Clarkey May 1 '14 at 14:50
  • 2
    @AvinashBabu Of course! I suggest you research into exactly what load balancing is first mate. – Clarkey May 1 '14 at 14:53
  • 1
    @AvinashBabu Yup, that's right! You can use the hostname or IP address. – Clarkey May 1 '14 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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