systemctl reload nginx with a broken configuration leaves the old one running and reports success in a way that is easy to miss, right up until the next restart takes the site down.
#!/usr/bin/env bash
set -euo pipefail
nginx -t
systemctl reload nginx
# and the check that the reload achieved something
sleep 1
curl -fsS -o /dev/null http://localhost/health
The set -e is what makes nginx -t a gate rather than a comment — without it the script prints the error and reloads anyway. The health check afterwards catches the other case, where the configuration is syntactically valid and semantically wrong, which a test cannot detect. Both together take under two seconds and turn a class of deploy failure into a failed deploy, which is a much better outcome.