🛠 Serveur web léger : nginx ou Caddy sur le Pi 2

Raspberry Pi 2 Model B (2015) — Board Sheet · avance · Schéma : IMG-model-2b-avance-3-model2b-serveur-web.svg — Raspberry Pi 2 Model B en serveur web derrière le routeur, nginx/Caddy servant une page vers un navigateur, 1 Go de RAM et Ethernet 100 Mbps mis en avant

Objectives

Turn the Pi 2 into a home web server. Its 1 GB of RAM and quad-core give it real headroom for a light service, but its 100 Mbps Ethernet shared with the USB bus caps network throughput: choosing a lean server (nginx or Caddy, not heavy Apache+PHP) is strategic. You will install the server, a static site, a systemd service, and measure the real throughput.

Hardware

Full code

# Option A : nginx (leger et classique)
sudo apt install nginx
sudo bash -c 'echo "<h1>Bonjour depuis le Pi 2</h1>" > /var/www/html/index.html'
sudo systemctl enable --now nginx

# Option B : Caddy (HTTPS automatique, binaire unique)
curl -1 https://r.caddy.sh | sudo bash -s
sudo bash -c 'echo "Pi2.example.com { root * /srv/pi2 }" > /etc/caddy/Caddyfile'
sudo systemctl enable --now caddy

# Vérifications locales
curl -I http://localhost
systemctl status nginx | head -n 5
free -h          # 1 GB de RAM : garder de la marge

# Débit réseau réel (attendu ~90 Mbit/s max)
sudo apt install iperf3 && iperf3 -c 192.168.1.10

Expected verification

curl -I http://localhost returns HTTP/1.1 200 OK; from another machine, http://IP-du-Pi displays the page. nginx consumes a few tens of MB, leaving 3/4 of the 1 GB available. iperf3 approaches 90 Mbit/s: beyond that, it is not the server but the 100 Mbps Ethernet port (shared USB bus) that limits.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials