TExcelTAD

How the Server Sessions Run

The sessions in this course start real servers: Nginx 1.24, HAProxy 2.8, Caddy 2.11 and Traefik 3.7, the versions in Ubuntu 24.04 and the current Caddy and Traefik releases. Each session runs in a fresh, empty Linux container as an ordinary user (learner), with no network and no root. This lesson shows the conventions every session follows, so the later ones can get straight to the point. They are the same as in Linux Server Administration.

Five conventions

  1. Ports ≥ 1024. Binding ports 80 and 443 needs root or CAP_NET_BIND_SERVICE, so sessions listen on 127.0.0.1:8080, 8443 and friends. Nothing else about the configuration changes.
  2. Everything in the working directory. Configs are written with heredocs; pid files, sockets, logs and cache folders live next to them. Nginx is started with -p "$PWD" (its prefix, the base for relative paths) and -c nginx.conf, and its config contains pid nginx.pid; and error_log stderr; so it never touches /run or /var/log.
  3. Backends are tiny Python servers. python3 -m http.server serves a folder; a ten-line http.server handler prints what it received, sleeps or fails on demand. They stand in for any app.
  4. Bounded waits. A server started in the background needs a moment. Sessions poll with a loop that gives up: for i in $(seq 50); do curl -s … && break; sleep 0.1; done. An unbounded until curl …; do sleep 1; done would hang forever if the server failed to start.
  5. Validate, start, query, stop. nginx -t, haproxy -c, caddy validate and Traefik's API come first; curl is the client; the session ends by stopping what it started.

A backend with knobs

Many lessons need a backend that does something specific: answers slowly, returns an error, reports which instance answered. This one reads its behaviour from the URL:

bash · try it yourself
cat > app.py <<'EOF'
import sys, time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
NAME, PORT = sys.argv[2], int(sys.argv[1])
class H(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path.startswith("/slow"): time.sleep(2)
        code = 500 if self.path.startswith("/fail") else 200
        self.send_response(code); self.send_header("Content-Type", "text/plain"); self.end_headers()
        self.wfile.write(f"{NAME} {code} {self.path}\n".encode())
    def log_message(self, *a): pass
ThreadingHTTPServer(("127.0.0.1", PORT), H).serve_forever()
EOF
python3 app.py 9001 app-a &
python3 app.py 9002 app-b &
for p in 9001 9002; do for i in $(seq 50); do curl -s 127.0.0.1:$p/ > /dev/null && break; sleep 0.1; done; done
curl -s 127.0.0.1:9001/orders
curl -s -w 'status=%{http_code}\n' 127.0.0.1:9002/fail
curl -s -o /dev/null -w 'slow request took about %{time_total}s\n' 127.0.0.1:9001/slow | sed -E 's/([0-9])\.[0-9]+s/\1s/'
ss -tlnH | awk '{print $4}' | sort
kill %1 %2
app-a 200 /orders
app-b 500 /fail
status=500
slow request took about 2s
127.0.0.1:9001
127.0.0.1:9002

ThreadingHTTPServer handles requests in parallel, which matters as soon as a lesson sends a slow request and a fast one at the same time. ss -tln lists the listening TCP sockets: here only the two backends. In later sessions it is a quick way to check that a proxy really bound the port you think.

Starting and stopping each server

Server Check Start (backgrounds itself) Stop
Nginx nginx -t -p "$PWD" -c nginx.conf -e stderr nginx -p "$PWD" -c nginx.conf -e stderr the same with -s quit (graceful)
HAProxy haproxy -c -f haproxy.cfg haproxy -D -f haproxy.cfg (with pidfile haproxy.pid) kill $(cat haproxy.pid)
Caddy caddy validate --config Caddyfile caddy start --config Caddyfile caddy stop (through the admin API on localhost:2019)
Traefik the API on its traefik entry point traefik --configFile=traefik.yml & kill %1

Nginx's -e stderr sets the error log used before the config is read; without it, nginx -t tries to open the compiled-in /var/log/nginx/error.log. Here is the whole cycle with a deliberate mistake first:

bash · try it yourself
mkdir www && echo "hello" > www/index.html
cat > nginx.conf <<'EOF'
pid nginx.pid;
error_log stderr;
events {}
http {
  access_log off;
  server {
    listen 127.0.0.1:8080;
    root www;
    locaton /api/ { return 200 "api\n"; }
  }
}
EOF
nginx -t -p "$PWD" -c nginx.conf -e stderr
sed -i 's/locaton/location/' nginx.conf
nginx -t -p "$PWD" -c nginx.conf -e stderr
nginx -p "$PWD" -c nginx.conf -e stderr
curl -s 127.0.0.1:8080/ 127.0.0.1:8080/api/x
ls
nginx -p "$PWD" -c nginx.conf -e stderr -s quit
2026/10/27 08:44:17 [emerg] 11#11: unknown directive "locaton" in /home/learner/nginx.conf:9
nginx: configuration file /home/learner/nginx.conf test failed
nginx: the configuration file /home/learner/nginx.conf syntax is ok
nginx: configuration file /home/learner/nginx.conf test is successful
hello
api
nginx.conf
nginx.pid
www
2026/10/27 08:44:17 [notice] 19#19: signal process started

The first check names the file and line of the typo; the [notice] … signal process started line at the end is -s quit reporting that it sent the signal to the running master. root www; is relative, so it resolves against the prefix (-p "$PWD"), and the temp folders Nginx needs for request bodies and proxied responses were created by the package in /var/lib/nginx (the image makes them writable for learner). On a server you would run sudo nginx -t against /etc/nginx/nginx.conf and reload with systemctl reload nginx; the checks and their messages are identical.

What stays a sample session

Needs Examples in this course
root or ports 80/443 the packaged systemd services, systemctl reload, binding :443
the internet public ACME certificates, Brotli modules from a package repository
a client the sandbox lacks HTTP/3 over QUIC (the sandbox's curl 8.5 has no HTTP/3 support)
Docker or Kubernetes Traefik's Docker and Kubernetes providers, Gateway API controllers

Those are shown as transcripts marked sample session, consistent with the real tools' output.

Test yourself

Why do the sessions poll with for i in $(seq 50); do curl … && break; sleep 0.1; done instead of until curl …; do sleep 1; done?

  1. It is faster
  2. The bounded loop gives up after 5 seconds, so a server that fails to start can't hang the session forever
  3. until is not valid bash
  4. curl needs a for loop

What does -p "$PWD" do for Nginx?

  1. Sets the port
  2. Sets the prefix that relative paths in the config (pid, root, logs) are resolved against
  3. Prints the config
  4. Runs as the current user