...

Open source softwares - NGINX

Back to Course

Lesson Description


Lession - #623 HTTP Health Checks


What is Health Checks?

A health check is a booked rule used to send a similar solicitation to every part. A wellbeing check sends a solicitation to every individual from the heap balancer gathering to lay out the accessibility of every part server to acknowledge the client demands. For certain kinds of wellbeing checks, the reaction from the server is determined to decide the wellbeing status of every part server. The fruitful consummation of the wellbeing check needs that the server passes typical TCP and HTTP association rules. In the TCP mode, a wellbeing check is performed with a TCP association demand. What's more, in the HTTP mode which is the standard wellbeing check type, a wellbeing check is performed with a HTTP GET or HTTP POST strategy.

HTTP Health Checks

Nginx Plus and Nginx open source can consistently test our upstream servers, keep away from the servers that have fizzled, and effortlessly add the recuperated servers into the heap adjusted bunch.

Passive Health Check

For passive health checks, Nginx Plus and Nginx screen the exchange as they occur, and attempt to continue the bombed associations. In the event that the exchange actually can't be continued, Nginx Plus and Nginx open-source mark the server as inaccessible and briefly quit sending solicitations to it until it is stamped dynamic once more. The conditions under which an upstream server is set apart as inaccessible are characterized for each upstream server with boundaries to the server order in the upstream square. Example: In the following example, if Nginx will fail to send a request to a server or if will not receive a response from it 3 times in 30 seconds, it will mark the server as unavailable for 30 seconds:

upstream backend {  
    server backend1.example.com;  
    server backend2.example.com max_fails=3 fail_timeout=30s;  
}  


Active Health Check

Nginx Plus occasionally checks the wellbeing of upstream servers by sending unique wellbeing really take a look at solicitations to every server and confirming the right reaction. To empower dynamic wellbeing checks: 1>
The location which passes solicitations to an upstream gathering, incorporate the health_check order:

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


2>
In the upstream server group, specify a shared memory zone with the zone directive:

http {  
    upstream backend {  
        zone backend 64k;  
        server backend1.example.com;  
        server backend2.example.com;  
        server backend3.example.com;  
        server backend4.example.com;  
    }  
} 
We can override the default for active health checks with parameters to the health_check directive:

location / {  
    proxy_pass http://backend;  
    health_check interval=10 fails=3 passes=2;  
}  


Specifying the Requested URI

We can use the uri parameter of the health_check directive to set the URI to request in a health check:

location / {  
    proxy_pass http://backend;  
    health_check uri=/some/path;  
}  
The predefined URI (Uniform Resource Identifier>
is annexed to the server area name or IP address set for the server in the upstream square. In the above model, for the main server in the example backend bunch, a wellbeing actually take a look at demands the URI http://backend1.example.com/some/way.

Defining Custom Conditions

We can indicate the custom circumstances that the reaction should fulfill for the server to pass the wellbeing check. The circumstances are characterized in the match block, which is referred to in the match boundary of the health_check mandate: 1>
On the http { } level, characterize the match {} square and give the name to it, for instance, server_ok:

http {  
    #...  
    match server_ok {  
        # tests are here  
    }  
}  


2>
Refer the square from the health_check mandate by characterizing the match boundary and the name of the match block:

http {  
    #...  
    match server_ok {  
        status 200-399;  
        body !~ "maintenance mode";  
    }  
    server {  
        #...  
        location / {  
            proxy_pass http://backend;  
            health_check match=server_ok;  
        }  
    }  
}  


nginx github

nginx github

haproxy vs nginx

haproxy vs nginx

nginx nodejs

nginx nodejs

nginx access logs

nginx access logs