Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://shop.example.com/healthz
200 0.084s
curl -sSI https://shop.example.com
curl -sS -X POST https://api.example.com/v1/orders -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -d '{"sku":"A-100","qty":2}'-s silent, -S but show errors, -o /dev/null hide the body, -w print what you want.
Step by step
- Status and time (quick answer) — the fastest health check.
- Headers and redirects:
curl -sSI http://shop.example.com
HTTP/1.1 301 Moved Permanently
Location: https://shop.example.com/
curl -sSIL http://shop.example.com | grep -E '^HTTP|^location'-I = headers only (HEAD request), -L = follow redirects.
- See everything (TLS, request and response headers) when something is wrong:
- Where does the time go? A timing breakdown:
curl -sS -o /dev/null -w 'dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} first-byte:%{time_starttransfer} total:%{time_total}\n' https://shop.example.com/
dns:0.012 connect:0.031 tls:0.074 first-byte:0.912 total:0.915Big first-byte minus tls = the server/app is slow; big dns or connect = network/DNS.
- Test a new server before DNS switches — send the right name to a specific IP:
curl -sSI --resolve shop.example.com:443:203.0.113.20 https://shop.example.com/TLS and virtual hosts work as if DNS already pointed there.
- APIs: JSON body, token, pretty output, and fail on HTTP errors in scripts:
curl -sS --fail-with-body -H "Authorization: Bearer $TOKEN" https://api.example.com/v1/orders/42 | jq .
curl -sS --retry 3 --retry-delay 2 --max-time 10 https://api.example.com/healthz--fail-with-body = exit code 22 on 4xx/5xx (CI stops) and still prints the error body.
- Only for tests:
-kskips TLS checks. Better:--cacert ca.crtfor an internal CA.
Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
curl: (6) Could not resolve host | DNS. | dig NAME; test with --resolve. |
curl: (7) Failed to connect | Nothing listens, or a firewall. | Test the port: nc -zv HOST 443. |
curl: (28) Operation timed out | Firewall drops, or the server hangs. | --max-time; check from another network; server logs. |
curl: (60) SSL certificate problem | Unknown CA, expired or wrong-name certificate. | curl -v; fix the cert or use --cacert. |
401 / 403 | Missing or wrong token, or no right. | Check the header; the token's scopes. |
| Token visible in shell history | Typed on the command line. | Use a variable from a file: TOKEN=$(cat token.txt), or -H @headers.txt. |
Go further
- Command pages: curl, jq, dig.
- Next how-tos: Check the TLS settings of a website, Test if a remote port is open, Find slow requests in Nginx logs.
- Learn it: curl in daily DevOps, jq, TLCL — curl and wget.
- Load tests: k6. Uptime checks: Uptime Kuma.
1How do you test a new server for shop.example.com before DNS points to it?
2In the timing output, first-byte is 0.9 s but tls is 0.07 s. Where is the time lost?
In the server or app (it needs about 0.8 s to start answering).