How to Turn a Raspberry Pi Zero W into a Mini Web Server – Step‑by‑Step Guide
This tutorial walks you through understanding what a Raspberry Pi Zero W is, preparing the hardware, flashing Raspbian Lite, enabling SSH and Wi‑Fi, installing Nginx, and exposing the server to the internet with ngrok, all with detailed commands and screenshots.
Introduction
The author discovered the Raspberry Pi and decided to document the entire process of turning a Raspberry Pi Zero W into a functional mini web server.
What Is a Raspberry Pi?
Raspberry Pi (RPi) is a credit‑card‑sized Linux‑based micro‑computer, popular among hobbyists. The Zero W model is a miniature version, about one‑third the size of a 3B+, with a 1 GHz single‑core CPU, 512 MB RAM, Wi‑Fi/Bluetooth, HDMI, USB, GPIO, and micro‑SD storage.
Zero W Specifications
BCM2835 processor, 1 GHz, 512 MB RAM
BCM43438 Wi‑Fi / BT chip
Micro‑USB power and OTG ports
Mini‑HDMI port
Composite video and reset pins
CSI camera connector
Micro‑SD slot for OS
40‑pin GPIO header
Dimensions: 65 mm × 30 mm
Installing the OS on Zero W
1. Preparation
Required items: a 16 GB or 32 GB SanDisk micro‑SD card, a standard USB‑type‑A cable, SDFormatter, Win32DiskImager, and the Raspbian Stretch Lite image.
2. Download the Image
Download the official Raspbian Stretch Lite zip (≈360 MB), unzip it to obtain a .img file (~1.7 GB).
3. Write Image to SD Card
Insert the SD card, open Win32DiskImager, select the .img file, choose the correct device, and click “Write”.
Note: If using a third‑party image, the extracted file may not be an .img; handle accordingly.
4. Configure Boot Partition
4.1 Create an empty ssh file
In the boot partition, create a file named ssh with no extension and no content to enable SSH on first boot.
4.2 Create wpa_supplicant.conf
Add the following to the file (replace with your Wi‑Fi SSID and password):
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="your_wifi_name"
psk="your_wifi_password"
}5. Assemble and Power Up
Insert the prepared SD card into the Zero W, connect power via the USB cable, and wait for the LED to become steady. Locate the device’s IP address on your router (e.g., 192.168.0.104).
6. Connect via SSH
Use an SSH client (e.g., PuTTY) to log in with username pi and password raspberry.
7. Optimize the System
7.1 Change APT Sources
Replace the default sources with a domestic mirror (e.g., USTC):
sudo nano /etc/apt/sources.list
# comment existing lines
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/raspbian stretch main contrib non-free rpi sudo nano /etc/apt/sources.list.d/raspi.list
# comment existing lines
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main ui sudo apt-get update
sudo apt-get upgrade7.2 Set Timezone
sudo dpkg-reconfigure tzdataSelect “Asia → Shanghai”.
7.3 Enable SSH on Boot
Method 1: sudo raspi-config → Interfacing Options → SSH → Enable.
Method 2: Add /etc/init.d/ssh start before exit 0 in /etc/rc.local.
8. Install Nginx
# Install
sudo apt-get install nginx
# Start
sudo /etc/init.d/nginx start
# Restart
sudo /etc/init.d/nginx restart
# Stop
sudo /etc/init.d/nginx stopAccess http://192.168.0.104 to verify the web server.
9. Expose the Server to the Internet (Port‑Forwarding)
Use a tunneling tool such as ngrok, frp, or domestic alternatives (ittun, sunny, natapp). The author uses the ngrok_arm binary from ittun.
Run ngrok in a screen session to keep it alive, and consider adding it to startup scripts for persistence.
Tip: On Android, you can use the “android terminal” app and run ip neigh to discover device IPs when using a phone hotspot.
Conclusion
The Raspberry Pi Zero W, despite its modest hardware, can comfortably host a small website, run Nginx, and be accessed remotely via ngrok, making it an excellent low‑cost platform for learning Linux, networking, and web services.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
