J
J
Jozo2018-02-07 17:34:13
Nginx
Jozo, 2018-02-07 17:34:13

How to setup Health check load balancer on nginx?

Hello, there are 3 nodes that are added to upstream on nginx. Services are raised on them:
1) Web
2) Transmission / reception of data via tcp (abbreviation mci)
Each port has its own API. The task is the following - it is necessary to check the availability of servers using their api using get (for web) and post (for tcp) requests.

stream {
    upstream mci_balancing {      
        server 172.22.5.32:37911 fail_timeout=3s;
        server 172.22.5.33:37911 fail_timeout=3s;
        server 172.22.5.34:37911 fail_timeout=3s;
    
    #По MCI - вот такой POST запрос <IRIS Version="1" Message="StatusRequest"></IRIS>			
  }
    server {
        listen        37911;
        proxy_pass    mci_balancing;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
}
http {
    upstream web_server {
    ip_hash; #для сохранения сессии авторизации
        server 172.22.5.32:8001;
        server 172.22.5.33:8001;
        server 172.22.5.34:8001;

#GET /?{%22request%22:%22ping%22

    keepalive 64;
    }
  server {
        listen 80;
        location / {
            proxy_pass http://web_server;
      proxy_redirect     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;
            proxy_set_header   X-Forwarded-Host $server_name;

    }
  }
}

In addition, for MCI, it is necessary to direct all traffic to 1 any working node and only when it fails, switch all traffic to another.
Tell me how you can implement standard or not very free nginx tools

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mrquokka, 2018-02-21
@mrquokka

ngx_stream_upstream_check_module for tcp (stream)
nginx_upstream_check_module for http (upstream)
But Haproxy is much more convenient, although there is a GPL v2 license, which is not suitable for me.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question