>_ IzzyLab

Hands-on task

This task is step 3 of the course “nginx basics”

Health Endpoint

medium~12 min

Add a service endpoint to nginx (port 80): GET /healthz must return status 200 and the body ok — fast, without touching files.

What you'll practise:
  • nginx
  • location
  • return
  • health-check
  • add_header

Topic breakdown

A health-check endpoint is a service URL that load balancers and orchestrators hit to find out whether an instance is alive; the main requirement is cheapness, without touching disk or DB. In nginx this is done with a location using an exact match (the = sign before the path), which rules out conflicts with prefix rules and speeds up the match. The response is built straight from the config with the return directive, giving it a code and a body string, and the content type, if needed, is set via default_type/add_header. After editing, the server rereads the config without a restart.

What's checked

  1. /healthz returns status 200
  2. /healthz returns the body ok
  3. nginx itself returns the response, no file involved

What it looks like