3

I want to map a particular domain in nginx, and then have nginx round-robin to a list of servers that will response to http requests.

So I have nginx for www.domain1.com

Its a python application, and I have 10 instances of paste running on different ports that I want nginx to forward/proxy requests to using round-robin.

can it do this, if yes, how?

Blankman
  • 2,841
  • 10
  • 38
  • 65

2 Answers2

3

You can specify ports for each backend server in an upstream block in nginx:

upstream mybackend  {
    server localhost:8080;
    server localhost:8081;
    server localhost:8082;
    server localhost:8083;
    server localhost:8084;
    server localhost:8085;
    server localhost:8086;
    server localhost:8087;
    server localhost:8088;
    server localhost:8089;
}

server {
  location / {
    proxy_pass  http://mybackend;
  }
}
rmalayter
  • 3,744
  • 19
  • 27
  • this is exactly what I have in my conf file but it isn't working. It just directs to the first one in the list. What am I doing wrong? – Normajean Jun 05 '21 at 03:35
  • @Normajean according to the linked docs it will round-robin, but only if you have things listening on those listed ports and returning non-error responses – rmalayter Jul 11 '21 at 12:36
0

Really, you'd be better off using something like haproxy for this, but nginx can reverse proxy to multiple servers at the backend.

Take a look at the upstream module for nginx http://wiki.nginx.org/NginxHttpUpstreamModule

Set upstream servers to the same weight for distributed round-robin balancing. e.g.

upstream backend { 
     server ww1.domain.com weight=10;
     server ww2.domain.com weight=10;
}

By default the weight is 1, so you technically don't need a weight of 10, but setting a higher default weight allows you to introduce a server with a lower weight easily.

Philip Reynolds
  • 9,751
  • 1
  • 32
  • 33
  • this server is already running nginx, can I run both w/o them conflicting? I need haproxy for a different domain, nginx is hosting 2 other domains for me. – Blankman Sep 08 '10 at 18:01