Fundamentals 12 min read

Step‑by‑Step Guide to Set Up Raspberry Pi Zero W with Raspbian, SSH, Nginx & Ngrok

This tutorial walks you through choosing a Raspberry Pi Zero W, flashing Raspbian Stretch Lite onto an SD card, configuring headless SSH access, installing and testing Nginx, and exposing the device to the internet using Ngrok, complete with hardware specs, command‑line snippets, and troubleshooting tips.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Step‑by‑Step Guide to Set Up Raspberry Pi Zero W with Raspbian, SSH, Nginx & Ngrok

Why Raspberry Pi Zero W?

The author discovered the Raspberry Pi series and decided to document the entire process of turning a low‑cost Zero W into a functional headless server.

What is a Raspberry Pi?

Raspberry Pi (RPi) is a credit‑card‑sized Linux‑based micro‑computer. The Zero W model is a miniature version (≈1/3 the size of a Pi 3 B+), featuring a 1 GHz BCM2835 CPU, 512 MB RAM, Wi‑Fi/Bluetooth, micro‑USB power and OTG, mini‑HDMI, GPIO pins, and a micro‑SD slot.

Hardware Specs

BCM2835 processor, 1 GHz

512 MB RAM

BCM43438 Wi‑Fi/BT chip

Micro‑USB power & OTG

Mini‑HDMI

CSI camera connector

40‑pin GPIO header

Dimensions: 65 mm × 30 mm

Preparing the SD Card

Required items:

16 GB or 32 GB SanDisk micro‑SD card

Standard USB‑A to micro‑USB cable (not Type‑C)

SD card formatter (e.g., SDFormatter)

Win32DiskImager (Windows)

Raspbian Stretch Lite image (official, headless)

1. Download the OS Image

Obtain the raspbian‑stretch‑lite.zip (≈360 MB), extract it to get the .img file (~1.7 GB).

2. Write the Image to the SD Card

Insert the micro‑SD card into a reader, launch Win32DiskImager, select the .img file, choose the correct device, and click Write.

3. Enable Headless SSH and Wi‑Fi

After writing, the card shows a single boot partition (≈40 MB). Open it and:

Create an empty file named ssh (no extension).

Create wpa_supplicant.conf 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="your_wifi_name"
    psk="your_wifi_password"
}

Booting the Zero W

Insert the prepared card into the Zero W, power it via the micro‑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).

SSH Login

Use an SSH client (e.g., PuTTY) to connect:

ssh [email protected]
Password: raspberry

System Optimisation

1. Change APT Sources

Replace the default mirrors with a faster domestic source (e.g., USTC):

sudo nano /etc/apt/sources.list
# comment existing lines and add:
deb http://mirrors.ustc.edu.cn/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 upgrade

2. Set Timezone

sudo dpkg-reconfigure tzdata
# select Asia → Shanghai

3. Enable SSH on Boot

Method 1 (raspi‑config):

sudo raspi-config
# Interface Options → SSH → Enable

Method 2 (rc.local): add the line before exit 0:

/etc/init.d/ssh start

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 stop

Visit http://192.168.0.104 in a browser to verify the default Nginx page.

Exposing the Service to the Internet

Use a tunnelling service such as Ngrok or FRP. The author tested three providers (ittun, sunny, natapp) and settled on ittun 's Ngrok ARM binary.

Typical usage (run in a screen session so it stays alive):

./ngrok_arm http 80

The public URL (e.g., http://zerow.ittun.com/) forwards traffic to the Pi’s internal Nginx server.

Additional Notes

The Zero W can run many other projects beyond a simple web server; the author encourages exploring tutorials on the official Raspberry Pi lab site.

Current system status (as of writing): Nginx and Ngrok running, ~250 MB free RAM, CPU temperature 37‑39 °C after two days of continuous operation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

NginxZero Wraspbianraspberry-pi
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.