Turn a Raspberry Pi Zero W into a Mini Web Server with SSH, Nginx & Ngrok
This guide walks you through selecting a low‑cost Raspberry Pi Zero W, flashing Raspbian Stretch Lite, configuring SSH and Wi‑Fi, optimizing the system, installing Nginx, and exposing the web service to the internet using ngrok, providing a compact, fully functional mini web server.
Introduction
After discovering the Raspberry Pi, I decided to document the whole process of turning a low‑cost Raspberry Pi Zero W into a functional mini web server.
What is Raspberry Pi?
Raspberry Pi (RPi) is a credit‑card‑sized Linux‑based micro‑computer. Despite its small size, it offers video, audio, GPIO, and other interfaces, making it a powerful platform for hobbyists and developers.
Raspberry Pi Zero W Overview
The Zero W is a miniature version of the Pi 3 B+, about one‑third the size. Key specifications:
BCM2835 processor, 1 GHz, 512 MB RAM
BCM43438 Wi‑Fi / BT chip
Micro‑USB power and OTG ports
Mini‑HDMI port
Composite video & reset pins
CSI camera connector
Micro‑SD slot for OS
40‑pin GPIO header
Dimensions: 65 mm × 30 mm
Preparation
Required items:
16 GB or 32 GB SanDisk micro‑SD card
Standard USB‑type‑A cable (not Type‑C)
SD card formatter (e.g., SDFormatter)
Win32DiskImager for flashing
Raspbian Stretch Lite image (download from the official site)
1. Download and Extract the System Image
Download the Raspbian Stretch Lite zip (≈360 MB), unzip it to obtain a .img file (~1.7 GB).
2. Write the Image to the SD Card
sudo dd if=raspbian.img of=/dev/sdX bs=4M status=progress conv=fsyncAlternatively, use Win32DiskImager: select the .img, choose the SD card device, and click “Write”.
3. Configure the Boot Partition
3.1 Enable SSH
Create an empty file named ssh (no extension) in the boot partition.
3.2 Configure Wi‑Fi
Create wpa_supplicant.conf in the boot partition with the following content (replace with your SSID and password):
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YourWiFiSSID"
psk="YourWiFiPassword"
}4. Assemble and Power Up
Insert the prepared SD card into the Zero W, connect power via a micro‑USB cable (5 V 1 A). After a few minutes the LED will stay solid, indicating boot completion.
5. Find the IP Address and SSH In
Check your router’s client list; the Zero W will appear (e.g., 192.168.0.104). Use an SSH client (e.g., PuTTY) to connect with username pi and password raspberry.
6. System Optimization
6.1 Change APT Sources
Replace the default sources with a faster mirror (e.g., USTC):
sudo nano /etc/apt/sources.list
# comment existing lines and add:
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 and add:
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main ui sudo apt-get update
sudo apt-get upgrade6.2 Set Timezone
sudo dpkg-reconfigure tzdataSelect “Asia → Shanghai”.
6.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.
7. 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 stopVisit http://192.168.0.104 in a browser to verify the Nginx welcome page.
8. Expose the Server to the Internet (Ngrok)
Use a tunneling service such as ngrok, frp, ittun, or natapp. The author prefers ittun’s ARM‑compatible ngrok client.
Run ngrok in a screen session to keep it alive in the background:
screen -S ngrok
./ngrok http 80Access the public URL (e.g., http://zerow.ittun.com/) to reach the web server from anywhere.
9. Additional Tips
The Zero W can run other services and projects; explore the Raspberry Pi Lab for more tutorials.
Current status: Nginx and ngrok running, ~250 MB free RAM, CPU temperature stable around 37‑39 °C after two days of operation.
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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
