Table of contents
1.
Introduction
2.
Prerequisites
3.
Passive Health Checks
4.
Active Health Checks
5.
FAQs
6.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

NGINX HTTP Health Checks

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

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. The response from the server is calculated at times to estimate the health status of each server. For a server to be healthy, it should pass the criteria of TCP or HTTP protocols.

HTTP mode is the standard health check type, and the health checks are performed for the HTTP GET or HTTP POST method, whereas, in TCP mode, the health checks are performed based on TCP protocol.

HTTP Health Checks is the monitoring of HTTP Servers by sending periodic health checks.

There are two types of health checks,

  • Passive Health Checks
  • Active Health Checks

Recommended Topic, Cognizant Eligibility Criteria

Prerequisites

  • If the user wants to perform an Active Health Check, the user requires NGINX Plus.
  • In case of a Passive Health check, NGINX Open Source or NGINX Plus is required.
  • The user will also need a group of HTTP upstream servers.

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

  1. 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.
     
  2. 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.
     
  3. What are the different types of Health Checks?
    There are two types of Health Checks,
    Active Health Check
    Passive Health Check
     
  4. 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
     
  5. 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.

Live masterclass