Question

I am listening on port 8080 with nginx and balance that on four tornado instances on ports 8081, 8081, 8083 and 8084 with nginx.conf bellow. How to force nginx to listen another port 8090 and balance that on port 8091, 8092, 8093 and 8094 ? Tornado instances running on [808*] are different than [809*]

8080 balance on [8081, 8082, 8083, 8084]
8090 balance on [8091, 8092, 8093, 8094]

there is nginx.conf

worker_processes 16;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;


#master_process off;
daemon off;

events {
    worker_connections 1024;
    use epoll;
}

http {
    charset utf-8;

    # Enumerate all the Tornado servers here
    upstream frontends {
        server 127.0.0.1:8081;
        server 127.0.0.1:8082;
        server 127.0.0.1:8083;
        server 127.0.0.1:8084;
    }

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    proxy_buffering off;
    proxy_buffers 4 512k;
    proxy_buffer_size 512k;

    access_log /var/log/nginx/access.log;

    #keepalive_timeout 65;
    #proxy_read_timeout 200;

    keepalive_timeout 600;
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1000;
    gzip_proxied any;
    gzip_types text/html text/plain text/css application/javascript application/x-javascript text/javascript text/xml application/xml;

    # Only retry if there was a communication error, not a timeout
    # on the Tornado server (to avoid propagating "queries of death"
    # to all frontends)
    proxy_next_upstream off;

    server {
        listen 8080;
        server_name localhost;

        location /
        {
            access_log off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        # Allow file uploads
        client_max_body_size 50M;


        location ^~ /static/ {
            root /home/server/;
            if ($query_string) {
                expires max;
            }
        }

    }
}
Was it helpful?

Solution

You need two upstream and two server blocks. Something like this (with other options filled in as before):

http {
  upstream eighties {
    server 127.0.0.1:8081;
    server 127.0.0.1:8082;
  }
  upstream nineties {
    server 127.0.0.1:8091;
    server 127.0.0.1:8092;
  }
  server {
    listen 8080;
    location / {
      proxy_pass http://eighties;
    }
  }
  server {
    listen 8090;
    location / {
      proxy_pass http://nineties;
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top