Fundamentals 11 min read

How to Turn a Raspberry Pi Zero W into a Tiny Web Server – Full Step‑by‑Step Guide

This article walks through the entire process of selecting a low‑cost Raspberry Pi Zero W, flashing Raspbian Stretch Lite, configuring SSH and Wi‑Fi, optimizing the OS, installing Nginx, and exposing the server to the internet with ngrok, complete with concrete commands, configuration files, and screenshots.

Java Web Project
Java Web Project
Java Web Project
How to Turn a Raspberry Pi Zero W into a Tiny Web Server – Full Step‑by‑Step Guide

Introduction

The author discovered the Raspberry Pi and decided to document the whole setup process for the ultra‑compact Zero W model.

What Is a Raspberry Pi?

Raspberry Pi (RPi) is a credit‑card‑sized Linux‑based micro‑computer designed for learning programming. The Zero W is a mini version roughly one‑third the size of a Model 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.

Preparing the System

16 GB or 32 GB SanDisk micro‑SD card

Standard USB‑type‑A Android data cable (not USB‑C)

SDFormatter for formatting

Win32DiskImager for flashing

Download the official Raspbian Stretch Lite image (≈360 MB zip, ≈1.7 GB img after extraction)

Flashing the Image

Extract the zip, locate the .img file, and use Win32DiskImager to write it to the SD card (select the image, choose the device, click “Write”).

Boot‑Partition Configuration

After flashing, the card shows a single boot partition (~40 MB) on Windows. Create two files in this partition:

ssh – an empty file with no extension to enable SSH on first boot.

wpa_supplicant.conf – contains 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 the micro‑USB cable, and wait for the LED to become steady. Find the device’s IP address on the router (e.g., 192.168.0.104) and connect with an SSH client (e.g., PuTTY) using the default credentials pi/raspberry.

System Optimisation

Changing APT Sources

Replace the default mirrors with a faster domestic source (e.g., USTC) by editing /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list: 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
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main ui

Then run:

sudo apt-get update
sudo apt-get upgrade

Setting Timezone

sudo dpkg-reconfigure tzdata

Select “Asia → Shanghai”.

Enabling SSH on Boot

Method 1: run sudo raspi-config, navigate to “Interfacing Options → SSH”, and enable.

Method 2: add /etc/init.d/ssh start before the exit 0 line in /etc/rc.local for automatic 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 see the default Nginx page, confirming a successful web server.

Exposing the Server to the Internet

In‑Network Tunnelling

Use a tunnelling service such as ngrok, frp, or domestic alternatives (ittun, sunny, natapp). The author found the ngrok_arm build from ittun works on the Zero W.

Run ngrok in a screen session to keep it alive after logout. The author notes that automatic start on reboot is still a missing piece.

Observations

After two days of continuous operation, the Zero W runs Nginx and ngrok with about 250 MB free RAM, CPU temperature stable between 37‑39 °C, demonstrating that the tiny board can comfortably host a lightweight web service.

Further Resources

For more models, tutorials, and community projects, visit the Raspberry Pi Lab website.

Raspberry Pi Zero W size comparison
Raspberry Pi Zero W size comparison
LinuxNginxtutorialraspberry-piSSHngrokZero W
Java Web Project
Written by

Java Web Project

Focused on Java backend technologies, trending internet tech, and the latest industry developments. The platform serves over 200,000 Java developers, inviting you to learn and exchange ideas together. Check the menu for Java learning 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.