Chapter 23. Web Servers and Application Hosting

Two pieces of software decide how a network's web services feel to their users: the server that terminates HTTP and TLS at the edge, and the application runtime behind it. This chapter runs both for real. Apache HTTP Server publishes name-based virtual hosts on one machine; Nginx terminates TLS for a static site, proxies an application, and feeds PHP-FPM on another; certificates come from a small private hierarchy that is built once, explained in depth, and then replaced by an automated ACME flow for a name that needs no manual certificate handling at all. The application behind the proxy is a deliberately small systemd service with a release layout, a health endpoint, a SQLite database, and a WebSocket companion, so that deployment, rollback, log correlation, and failure diagnosis can be exercised without a framework in the way.

The four Debian 13 machines and their addresses on the practice LAN:

Host Role Practice interface Administration
web1 Apache HTTP Server; private root and issuing CA; internal dnsmasq resolver; Pebble ACME test server eth1 - 192.168.234.10/24 eth0 - management network, 192.168.121.0/24
web2 Nginx edge: static TLS site, reverse proxy for the application, PHP front end eth1 - 192.168.234.11/24 eth0 - management network
app1 application service on TCP 8080; WebSocket echo on 8081; Unix socket; PHP-FPM pool on 9000; SQLite state; nftables backend filter eth1 - 192.168.234.12/24 eth0 - management network
client1 ordinary client: curl, openssl, a Python WebSocket client eth1 - 192.168.234.20/24 eth0 - management network

The chapter 23 practice network

Figure 23.1. One isolated practice LAN carrying all exercise traffic. web1 answers Apache sites and the lab's DNS and CA needs; web2 is the TLS-terminating edge; app1 runs the application runtime and PHP-FPM; client1 makes the requests. Every host keeps a management interface for SSH that no exercise touches.

The management network is the same insurance Chapter 21 and Chapter 22 relied on: practice work uses eth1 only, so a broken virtual host or a mis-filtered port cannot cost administrative access. The interfaces were configured with the tools of Chapter 17; reach the hosts over SSH as covered in Chapter 20. Commands entered in john's ordinary shell begin with $ and commands entered in a root shell begin with #; the prompt marker itself is not typed. Single elevated steps are written $ sudo command, which asks for john's password the first time in a session (the password is not echoed); sustained administrative work can open a root shell with $ sudo -i, whose prompt is # and which exit leaves. john holds administrative rights through the sudo delegation of Chapter 5; if your site delegates differently, adapt the elevated commands to its method. Before each command block the text names the host it runs on.

Example files, certificate material, and practice data live under a named workspace in john's home directory. Create it on every host the chapter works on - here on web1, and the same command applies on web2, app1, and client1:

$ mkdir -p ~/debian-handbook/web-services

The command prints nothing on success. Sections that store several related files also create a subdirectory, such as fixtures/apache, before writing into it. Where a step changes the working directory, the text says so; otherwise commands run from the workspace root, and paths like fixtures/nginx/static.conf are relative to it. Tilde expansion follows the account: after sudo -i, ~ is /root, not john's home, so the elevated install commands below always spell john's paths out in full.

All four practice guests run the same Debian 13.5 with kernel 6.12.86+deb13-amd64; the captures in this chapter come from them. On web1, in john's shell:

$ cat /etc/debian_version
13.5
$ uname -r
6.12.86+deb13-amd64

The sections install their packages as they reach them; the inventory below is the complete web-facing set on the three servers once every section has run. On web1, in john's shell:

$ dpkg-query -W apache2 openssl certbot pebble dnsmasq ssl-cert
apache2 2.4.71-1~deb13u1
certbot 4.0.0-2~deb13u1
dnsmasq 2.91-1+deb13u2
openssl 3.5.9-1~deb13u1
pebble  2.6.0+ds1-1+b7
ssl-cert    1.1.3

On web2:

$ dpkg-query -W nginx openssl curl
curl    8.14.1-2+deb13u7
nginx   1.26.3-3+deb13u11
openssl 3.5.9-1~deb13u1

And on app1:

$ dpkg-query -W php-fpm python3 python3-websockets sqlite3 nftables curl
curl    8.14.1-2+deb13u7
nftables    1.1.3-1
php-fpm 2:8.4+96
python3 3.13.5-1
python3-websockets  15.0.1-1
sqlite3 3.46.1-7+deb13u2

client1 needs no server packages; it uses the base system's curl 8.14.1 and openssl 3.5.9 plus python3-websockets 15.0.1 for the WebSocket exercise in Section 23.5.3.

In this section