A tiny health-check endpoint for Nginx

The load balancer kept sending traffic to a server that was up but not ready. A proper health check fixed that.

The pipeline as documentation

The on-call rota rotates weekly, and whoever is on call does no planned work. Quiet weeks become time for fixing the alerts that woke us up.

location = /healthz {
    access_log off;
    default_type text/plain;
    fastcgi_pass php-fpm;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/healthz.php;
}

upstream php-fpm {
    server 127.0.0.1:9000 max_fails=2 fail_timeout=10s;
}

Our deploy pipeline is the most accurate documentation we have. If a step is not in the pipeline, it does not happen, and nobody has to remember it. The snippet above is the whole thing; the version in our repository only adds tests.

Keeping on-call humane

  • Alert on symptoms, not causes
  • Keep one runbook per alert
  • Rotate on-call weekly and protect that time
  • Write a blameless review for every incident

4 comments on “A tiny health-check endpoint for Nginx”

  1. Clear and practical, thank you. One question: how long did the whole change take from start to finish?

  2. Small thing, but thank you for including the numbers. So many posts skip that part.

    1. Elin Sørensen

      Good question. It took about three weeks, most of it waiting for review and measuring the results.

Leave a comment

Your email address will not be published. Required fields are marked *