Turn a Raspberry Pi Zero W into a Tiny Web Server with SSH, Nginx & Ngrok
This guide walks you through selecting a low‑cost Raspberry Pi Zero W, flashing Raspbian Lite, enabling SSH and Wi‑Fi via boot‑partition files, configuring the system, installing Nginx, and exposing the site to the internet using ngrok, providing a compact, fully functional web‑hosting platform.
What is Raspberry Pi Zero W?
Raspberry Pi (RPi) is a credit‑card‑sized Linux‑based micro‑computer. The Zero W model is a mini version about one‑third the size of a Pi 3 B+, featuring a 1 GHz single‑core CPU, 512 MB RAM, Wi‑Fi/Bluetooth, micro‑USB power and OTG, mini‑HDMI, GPIO pins, and a micro‑SD slot.
Choosing the hardware
The author selected a low‑cost Zero W (≈100 CNY) after finding the standard 3 B+ board too expensive.
Preparing the system
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
Raspbian Stretch Lite image (official, no desktop)
The Lite image is a 360 KB zip that expands to a ~1.7 GB .img file.
Writing the image
Insert the SD card into a reader, open Win32DiskImager, select the .img file, choose the device, and click “Write”.
Configuring boot files
After writing, the SD card shows a boot partition (≈40 MB). Create two empty files in this partition:
ssh – an empty file to enable SSH on first boot.
wpa_supplicant.conf – containing Wi‑Fi credentials:
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YOUR_WIFI_NAME"
psk="YOUR_WIFI_PASSWORD"
}First boot and SSH access
Insert the card into the Zero W, power it via a USB cable, wait for the LED to stay solid, then find its IP (e.g., 192.168.0.104) on the router. Connect with an SSH client (e.g., PuTTY) using username pi and password raspberry.
System optimisation
Changing package sources
Replace the default apt sources with a domestic mirror (e.g., USTC) by editing /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list, then run:
sudo apt-get update
sudo apt-get upgradeSetting timezone
sudo dpkg-reconfigure tzdataSelect Asia → Shanghai.
Enabling 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.
Installing 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://<em>your_pi_ip</em> in a browser to see the default Nginx page.
Exposing the server to the internet
Use a tunneling service such as ngrok, ittun, or natapp. The author chose the arm version of ittun’s ngrok, running it inside a screen session for background execution.
Additional notes
The Zero W can run other projects beyond a web server; many resources are available on the Raspberry Pi Lab website.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
