Passive Health Checks
In Passive Health Check, the NGINX or NGINX Plus continuously monitors the transactions and tries to resume them as the transactions happen. In case the transaction cannot be resumed, it is marked as unavailable or temporarily closed so that no requests are sent to it until it is marked as active.
Example,
upstream back {
server backend1.example1.com;
server backend2.example1.com max_fails=5 fail_timeout=60s;
}

You can also try this code with Online Python Compiler
Run Code
In the above example, NGINX will mark the server as inactive,
- If NGINX cannot reach the server.
- If NGINX doesn't receive a response from the server at least five times in one minute.
Also see, Must Do Coding Questions
Active Health Checks
In Active Health Checks, NGINX Plus periodically sends health check requests to each server and waits for an accurate reply.
Active Health Checks can be enabled:
1) The location which passes requests to an upstream group, include the health_check directive,
server {
location / {
proxy_pass http://back;
health_check;
}
}

You can also try this code with Online Python Compiler
Run Code
2) We will need to specify a shared memory zone in the upstream server group,
http {
upstream back {
zone backend 64k;
server backend1.example1.com;
server backend2.example1.com;
server backend3.example1.com;
server backend4.example1.com;
}
}

You can also try this code with Online Python Compiler
Run Code
Also Read - Ibegin TCS
We can even customize the Active Health Check settings by passing various parameters to the health_check directive,
location / {
proxy_pass http://back;
health_check interval=15 fails=5 passes=4;
}

You can also try this code with Online Python Compiler
Run Code
We can also pass the uri parameter in the health_check directive to set the URI request in the Health Check,
location / {
proxy_pass http://back;
health_check uri=/some/path;
}

You can also try this code with Online Python Compiler
Run Code
You can also read about mock interview.
FAQs
-
What is NGINX?
NGINX is a web server, and it can also be used as a reverse proxy, mail proxy, HTTP cache, and load balancer.
-
What is a Health Check?
Health Check is a set of rules used to send a request to each member of the group to establish the availability of member servers to accept the incoming client requests.
-
What are the different types of Health Checks?
There are two types of Health Checks,
Active Health Check
Passive Health Check
-
What are the benefits of using NGINX?
NGINX provides a lot of benefits like,
Standardized JSON Configuration Files
HTTP configuration API
Consistent networking layer
Reconfiguration without restarts
-
How does TCP Health Check Work?
In TCP Health Check, the health check attempts to open a TCP connection to the instance on the specified port.
Key Takeaways
This Blog covered all the necessary points about NGINX HTTP Health Checks and the essential steps to perform a Health Check.
Don’t stop here; check out Coding Ninjas for more unique courses and guided paths. Also, try Coding Ninjas Studio for more exciting articles, interview experiences, and fantastic Data Structures and Algorithms problems.