Javatpoint Logo
Javatpoint Logo

NGINX UDP Health Checks

Here, we will discuss how to configure different types of health checks for UDP (User Datagram Protocol) servers in a load-balanced upstream server group.

We have configured an upstream group of servers that handles UDP network traffic (DNS, RADIUS, Syslog) in the stream { } context, for example:

And we have configured a server that passes UDP datagrams to the upstream server group.

Passive UDP Health Checks

Nginx Plus or Nginx open source can mark the server as unavailable and stop sending UDP datagrams to it for some time is the server replies with an error or times out.

The number of consecutive failed connection attempts within a certain period is set with the max_fails parameter for an upstream server. (Default is 1).

The time is set with the fail_timeout parameter (default is 10 seconds). The parameter also sets the amount of time that Nginx considers the server unavailable after making it so.

So, if a connection attempt times will out or fails at least once in a 10 second period, Nginx marks the server as unavailable for 10 seconds. The following example shows how to set these parameters to two failures within 60 seconds.

Active UDP Health Checks

Active Health Checks allow checking a wider range of failure types and are available only for Nginx Plus. E.g., instead of waiting for an actual TCP request from a DNS server as down, Nginx Plus will send special health check requests to each upstream server and check for a response that satisfies certain conditions.

If a connection to the server can't be established, the health check fails, and the server is considered unhealthy. Nginx Plus doesn't make proxy client connections to unhealthy servers. If more than one health check is specified, the failure of any check is enough to consider the corresponding upstream server unhealthy.

To enable active health checks:

1. In the group of upstream, define a shared memory zone with the zone directive-a special area where the Nginx Plus worker processes share state information about counters and connections. In the zone directive, specify the zone name and zone size. (Here, dns_zone is the zone name, and 64k is the zone size).

2. In the block of the server that forwards traffic to the upstream group (through proxy_pass), specify the UDP parameter to the health_check directive.

Fine-Tuning UDP Health Checks

We can fine-tune the health check by specifying the following given parameters to the health_check directive:

interval: It defines how often Nginx Plus sends health check requests within seconds(default is 5 seconds).

passes: Several consecutive health checks that the server must respond to be considered healthy. The default value is 1.

fails: Some consecutive health checks that the server must fail to respond to be considered unhealthy. The default value is 1.

In the above example, the time between UDP health checks is increased to 20 seconds. The server is considered unhealthy after two consecutive failed health checks, and the server needs to pass two consecutive checks to be considered healthy again.

Next Topic#

Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA