Turn a Raspberry Pi Zero W into a Tiny Web Server with SSH and Ngrok
This step‑by‑step guide shows how to set up a Raspberry Pi Zero W with Raspbian Lite, enable headless SSH, configure Wi‑Fi, install Nginx, and expose the server to the public internet using Ngrok, turning a credit‑card‑sized board into a functional web host.
Understanding the Raspberry Pi Zero W
The Raspberry Pi (RPi) is a credit‑card‑sized Linux‑based computer; the Zero W is a mini version about one‑third the size of a 3B+, featuring a 1 GHz BCM2835 CPU, 512 MB RAM, Wi‑Fi/BT, micro‑USB ports, mini‑HDMI, GPIO, and a 65 mm × 30 mm form factor.
Required Materials
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 images
Raspbian Stretch Lite image (official, console‑only)
Step 1 – Download the OS Image
Obtain the official Raspbian Stretch Lite zip (≈360 MB), extract it to reveal a ~1.7 GB *.img file.
Step 2 – Flash the Image to the SD Card
Insert the micro‑SD card via a reader, open Win32DiskImager, select the *.img file, choose the correct device, and click “Write”.
Step 3 – Prepare the Boot Partition
Create an empty file named ssh (no extension, no content) to enable SSH on first boot.
Create wpa_supplicant.conf with the following content (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"
}Step 4 – Boot and Connect via SSH
Insert the prepared card into the Zero W, power it with a 5 V 1 A USB cable, wait for the LED to become steady, then locate its IP address on your router (e.g., 192.168.0.104). Connect with an SSH client (e.g., PuTTY) using username pi and password raspberry.
Step 5 – System Optimisation
Replace default apt sources with a faster domestic mirror (e.g., USTC).
Run sudo apt-get update && sudo apt-get upgrade.
Set timezone to Asia/Shanghai with sudo dpkg-reconfigure tzdata.
Enable SSH on boot via sudo raspi-config (Interfacing Options → SSH) or by adding /etc/init.d/ssh start before exit 0 in /etc/rc.local.
Step 6 – 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 stopBrowse to http://<em>your_pi_ip</em> to verify the Nginx welcome page.
Step 7 – Expose the Server to the Internet
Use a tunnelling service such as ngrok (e.g., the ittun arm build) to forward the local web port. Run ngrok in a screen session so it stays alive after logout.
Additional Resources
For more Raspberry Pi models and tutorials, visit the official 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.
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.
