TExcelTAD
Home › Web Servers in Depth: Nginx, HAProxy, Caddy & Traefik › Toolkit: The Proxy Engineer's Bench

Toolkit: The Proxy Engineer's Bench

The commands from this course in one place: how to check, start, reload and inspect each server, the curl and openssl recipes for testing a proxy from outside, and the tools for load testing. Keep it next to your terminal.

Check, apply, inspect

Nginx HAProxy Caddy Traefik
validate nginx -t haproxy -c -f haproxy.cfg caddy validate --config Caddyfile traefik logs errors; check the API (/api/http/routers)
show effective config nginx -T haproxy -c -f … -dD (diagnostics), Runtime API show … caddy adapt --pretty, GET :2019/config/ GET /api/rawdata
apply systemctl reload nginx systemctl reload haproxy caddy reload / systemctl reload caddy providers (file watch, labels, CRDs)
live changes – Runtime API (socat on the stats socket) admin API (curl :2019/…) edit the dynamic config
format – – caddy fmt --overwrite yamllint / yq
status/metrics stub_status stats page, /metrics :2019/metrics dashboard, /metrics

Testing a proxy from outside with curl

Need Command
Test a name before DNS points at the server curl --resolve shop.example:443:203.0.113.10 https://shop.example/
Send a different Host over plain HTTP curl -H 'Host: shop.example' http://10.0.0.5/
See only the response headers curl -sS -D - -o /dev/null URL (-I sends HEAD, which some apps handle differently)
Force a protocol --http1.1, --http2, --http3 (if built with it); -w '%{http_version}' shows the result
Check compression -H 'Accept-Encoding: gzip, br, zstd', look at Content-Encoding
Follow redirects and show them -sSL -w '%{num_redirects} redirects -> %{url_effective}\n'
Client certificate --cert client.crt --key client.key --cacert ca.crt
Timing breakdown the -w template below

The timing template splits a request into DNS, TCP connect, TLS handshake, waiting for the first byte (backend time plus proxy overhead) and transfer. Here it runs against Nginx proxying to a backend that takes about 0.3 s:

bash · try it yourself
cat > app.py <<'EOF'
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
class H(BaseHTTPRequestHandler):
    def do_GET(self):
        time.sleep(0.3); self.send_response(200); self.end_headers(); self.wfile.write(b"report\n")
    def log_message(self, *a): pass
HTTPServer(("127.0.0.1", 9000), H).serve_forever()
EOF
python3 app.py &
openssl req -x509 -new -noenc -newkey ec -pkeyopt ec_paramgen_curve:P-256 -keyout site.key -out site.crt -days 30 \
  -subj "/CN=shop.example.test" -addext "subjectAltName=DNS:shop.example.test" 2>/dev/null
cat > nginx.conf <<'EOF'
pid nginx.pid;
error_log stderr;
events {}
http {
  access_log off;
  server {
    listen 127.0.0.1:8443 ssl;
    ssl_certificate site.crt; ssl_certificate_key site.key;
    location / { proxy_pass http://127.0.0.1:9000; }
  }
}
EOF
for i in $(seq 50); do curl -s 127.0.0.1:9000/ > /dev/null && break; sleep 0.1; done
nginx -p "$PWD" -c nginx.conf -e stderr
cat > timing.txt <<'EOF'
   dns lookup:  %{time_namelookup}\n
  tcp connect:  %{time_connect}\n
tls handshake:  %{time_appconnect}\n
   first byte:  %{time_starttransfer}\n
        total:  %{time_total}\n
EOF
curl -s -o /dev/null -w @timing.txt --resolve shop.example.test:8443:127.0.0.1 --cacert site.crt https://shop.example.test:8443/ > t.txt
# The values are cumulative seconds since the start; print them rounded to 0.1 s so they are stable here.
awk -F: '{printf "%s: %.1f s\n", $1, $2}' t.txt
nginx -p "$PWD" -c nginx.conf -e stderr -s quit 2>/dev/null; kill %1
   dns lookup: 0.0 s
  tcp connect: 0.0 s
tls handshake: 0.0 s
   first byte: 0.3 s
        total: 0.3 s

All values are cumulative. Here DNS, TCP and TLS are near zero (loopback), and nearly all the time is between the end of the handshake and the first byte: the backend. On a real slow request, the same template tells you at a glance whether to look at the network (connect), certificates and TLS settings (handshake), or the app (first byte).

openssl for TLS questions

Question Command
Which certificate and chain does the server send for this name? openssl s_client -connect host:443 -servername name -showcerts </dev/null
Protocol and cipher … -brief
Is TLS 1.1 refused? … -tls1_1 (expect a handshake failure)
ALPN (HTTP/2)? … -alpn h2,http/1.1 → ALPN protocol: h2
When does the served certificate expire? `…
Does a key match a certificate? compare openssl pkey -in key -pubout with openssl x509 -in crt -noout -pubkey

Load testing

Tool Strength Example
ab (ApacheBench) everywhere, simple; HTTP/1.0, one URL ab -n 10000 -c 100 https://shop.example/
wrk / wrk2 very high load from one machine; Lua scripting; wrk2 keeps a constant rate (honest latency percentiles) wrk -t4 -c200 -d30s --latency URL
hey / oha simple, HTTP/2 support oha -z 30s -c 50 --http2 URL
k6 scripted scenarios in JavaScript, thresholds, CI-friendly k6 run script.js
vegeta constant-rate attacks, good reports echo "GET URL" | vegeta attack -rate=500 -duration=30s | vegeta report

None of them is in the course sandbox; run them from a separate machine, never from the proxy host itself (the load generator would compete for the CPU you are measuring), and test with production-like TLS, keep-alive and payloads. Measure latency at a fixed request rate, not just maximum throughput: a proxy that does 50,000 requests per second with a p99 of 2 seconds is worse than one doing 20,000 with a p99 of 20 ms.

Debugging

  • ss -tlnp / ss -ulnp: what listens where (UDP for HTTP/3).
  • The error logs: Nginx error_log … info temporarily, HAProxy show errors, Caddy debug global option, Traefik log.level: DEBUG.
  • tcpdump -i any -nn port 9000 between proxy and backend shows whether a request reached the app at all (tcpdump Recipes).
  • strace -f -p <worker pid> -e trace=network on a worker answers "what is it waiting for?".

Test yourself

Which command shows the configuration Caddy actually runs, as JSON?

  1. caddy fmt
  2. caddy adapt --config Caddyfile --pretty (or GET :2019/config/ on a running Caddy)
  3. caddy validate
  4. caddy list-modules

In a curl timing breakdown, almost all time is between tls handshake and first byte. Where should you look?

  1. DNS
  2. The network path
  3. The backend (or the proxy's queue in front of it)
  4. The certificate

Why measure latency percentiles at a fixed request rate instead of only maximum throughput?

  1. It is faster
  2. Maximum-throughput tests hide queueing; users experience latency at realistic rates, and tail latency is what hurts
  3. Tools require it
  4. Throughput can't be measured