🛠 Héberger un serveur web léger

Raspberry Pi 3 Model B (model-3b) · avance · Schéma : IMG-model-3b-avance-3-model3b-serveur-web-leger.svg — Raspberry Pi 3 Model B servant un site statique sur le port 8080, service systemd, clients du réseau local connectés par Ethernet/Wi-Fi, contrainte mémoire 1 Go rappelée

Objectives

Transform the Raspberry Pi 3 Model B into a permanent small web server: serve a static site, wrap it in a systemd service (automatic startup + restart on crash), and respect the 1 GB memory constraint which requires lightweight servers. This is the building block for a home dashboard, a Pi-hole-like setup, or a connected mirror.

Hardware

Complete code

# 1) Dossier du site
mkdir -p ~/site && echo '<h1>Pi 3B opérationnel</h1>' > ~/site/index.html

# 2) Service systemd — serveur Python intégré, port 8080
sudo tee /etc/systemd/system/pisite.service <<'EOF'
[Unit]
Description=Site statique du Pi 3B
After=network-online.target

[Service]
User=pi
WorkingDirectory=/home/pi/site
ExecStart=/usr/bin/python3 -m http.server 8080 --bind 0.0.0.0
Restart=always
RestartSec=3
MemoryMax=200M

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now pisite
sudo systemctl status pisite --no-pager

# 3) Test local puis distant
curl -s http://localhost:8080/ | head -1
#   depuis un autre poste : curl http://raspberrypi.local:8080/

Expected verification

systemctl status pisite displays active (running). curl http://localhost:8080/ returns the site's <h1>, and from another machine on the network, http://raspberrypi.local:8080/ displays the page in the browser. After killing the process, systemd restarts it within 3 seconds. systemd-run/free -m shows the memory footprint below the MemoryMax=200M limit. After a full reboot, the service starts automatically.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials