Operations 14 min read

Turn a Raspberry Pi Zero W into a Mini Web Server: Complete Step‑by‑Step Guide

This guide walks you through the entire process of setting up a Raspberry Pi Zero W—from understanding the hardware and its specifications, flashing Raspbian Stretch Lite, configuring SSH and Wi‑Fi, optimizing the system, installing Nginx, to exposing the server publicly via ngrok—providing all commands, configuration files, and troubleshooting tips.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Turn a Raspberry Pi Zero W into a Mini Web Server: Complete Step‑by‑Step Guide

1. Introduction

The author discovered the Raspberry Pi Zero W and decided to document the whole setup process as a learning exercise.

2. What Is Raspberry Pi?

Raspberry Pi (often abbreviated RPi) is a credit‑card‑sized micro‑computer designed for education and hobbyist projects. It runs a Linux‑based OS and, with Windows 10 IoT, can also run Windows.

2.1 Simple Explanation

Think of the Pi as a tiny PC: you can attach a monitor, keyboard, mouse, USB drives, etc. Despite its small size, it offers GPIO pins, serial ports, HDMI, and other interfaces for low‑level hardware access.

2.2 Available Models

The most common model on the market is the 3‑generation B+. Prices for a bare board are around 230 CNY, which may be above some budgets.

2.3 Raspberry Pi Zero W

The Zero W is a miniature version roughly one‑third the size of a 3B+. It includes Wi‑Fi, Bluetooth, and a mini‑HDMI port. The article includes a photo showing the board alongside a USB Wi‑Fi dongle and a USB card reader.

BCM2835 processor, 1 GHz, 512 MB RAM

BCM43438 Wi‑Fi/BT chip

Micro‑USB power port

Micro‑USB OTG port

Mini‑HDMI port

Composite video & reset pins

CSI camera connector

Micro‑SD slot for the OS

40‑pin GPIO header

Dimensions: 65 mm × 30 mm

Although it has a single‑core CPU and limited RAM, it is capable of running a small website.

3. Installing the OS on Raspberry Pi Zero W

3.1 Required Materials

16 GB or 32 GB SanDisk micro‑SD card

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

SD card formatting tool (e.g., SDFormatter)

Image‑writing tool ( Win32DiskImager)

Raspberry Pi OS image (download from the official site)

The author uses the Raspbian Stretch Lite image, a minimal console‑only version that saves space and resources.

3.2 Download and Extract the Image

After downloading the zip file (≈360 MB), unzip it to obtain a .img file (~1.7 GB).

unzip raspbian-stretch-lite.zip

3.3 Write the Image to the SD Card

Insert the SD card into a reader, launch Win32DiskImager, select the .img file, choose the correct device, and click “Write”. A success dialog confirms completion.

3.4 Enable SSH

Create an empty file named ssh (no extension) in the boot partition. This causes SSH to be enabled on first boot.

3.5 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="YOUR_WIFI_SSID"
    psk="YOUR_WIFI_PASSWORD"
}

3.6 Assemble and Power Up

Insert the prepared SD card into the Zero W, connect power via a 5 V 1 A USB cable, and wait for the LED to become steady. The device will obtain an IP address from the router.

Find the IP address (e.g., 192.168.0.104) and connect via SSH (default user pi, password raspberry).

4. System Optimization

4.1 Change Package Sources

To improve download speed in China, replace the default sources with the University of Science and Technology of China mirrors. sudo nano /etc/apt/sources.list Comment out 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
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main ui
sudo apt-get update
sudo apt-get upgrade

4.2 Set Timezone

sudo dpkg-reconfigure tzdata

Select “Asia/Shanghai”.

4.3 Enable SSH on Boot

Method 1: Run sudo raspi-config, go to “Interfacing Options → SSH”, and enable it.

Method 2: Edit /etc/rc.local and add /etc/init.d/ssh start before the exit 0 line.

5. 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 stop

Access the server in a browser at the Pi’s IP address to verify the Nginx welcome page.

6. Expose the Server to the Internet (Port‑Forwarding)

Because the Pi is behind a NAT, use a tunneling service such as ngrok or frp. The author tried several providers and settled on the ittun version of ngrok (named ngrok_arm) that runs on ARM.

Run ngrok in a screen session so it stays alive after logout. Note that automatic start on boot is not yet implemented.

7. Final Remarks

The Raspberry Pi Zero W can serve a lightweight website, run Nginx, and be accessed publicly via a tunneling service, all while consuming less than 250 MB of RAM and maintaining a modest CPU temperature.

LinuxNginxIoTraspberry-piSSHSystem SetupngrokZero W
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

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.