Operations 12 min read

How to Turn a Raspberry Pi Zero W into a Tiny Web Server with SSH and Nginx

This step‑by‑step guide shows how to set up a Raspberry Pi Zero W, flash Raspbian Stretch Lite, configure Wi‑Fi and SSH, optimize the system with local mirrors, install Nginx, and expose the server to the internet using ngrok, turning a credit‑card‑sized board into a functional web host.

Java Captain
Java Captain
Java Captain
How to Turn a Raspberry Pi Zero W into a Tiny Web Server with SSH and Nginx

Preface

The author discovered the Raspberry Pi, found it fascinating, and decided to document the entire setup process.

What Is a Raspberry Pi?

Raspberry Pi (RPi) is a credit‑card‑sized micro‑computer designed for learning programming, running a Linux‑based OS. It offers video, audio, and many I/O capabilities despite its tiny form factor.

In the author's words, it is a full‑featured host that can connect a monitor, keyboard, mouse, USB drives, and other peripherals, thanks to its numerous ports and GPIO pins.

Most common models are the 3‑generation B+ boards, priced around 230 CNY for the bare board, which the author found too expensive and therefore sought a cheaper alternative.

Raspberry Pi Zero W

The Zero W is a miniature version, roughly one‑third the size of a 3B+. It is extremely small and cute, as shown in the accompanying photos.

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 and reset pins

CSI camera interface

Micro‑SD card slot for the OS

40‑pin GPIO header

Dimensions: 65 mm × 30 mm

Despite its single‑core CPU and modest memory, it performs well enough to run a small website.

Installing the OS on Zero W

Preparation

16 GB or 32 GB SanDisk micro‑SD card

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

SDFormatter utility

Win32DiskImager utility

Raspberry Pi OS image (download from the official site)

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

1. Download the OS image

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

Note: Official Raspbian images contain an .img file; third‑party images may differ.

2. Write the image to the SD card

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

In the screenshot the device is not selected because no card was inserted.

3. Modify the boot partition

The boot partition (≈40 MB) is visible on Windows. Create an empty file named ssh (no extension) 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"
}

4. Assemble and power up

Insert the prepared card into the Zero W, connect power via a USB cable, and wait for the LED to stay solid. Then locate the Pi’s IP address on the router.

Use an SSH client (e.g., PuTTY) to connect with username pi and password raspberry.

If using a phone hotspot, you can install the “android terminal” app and run ip neigh to discover the device’s IP.

Optimizing the System

6.1 Change apt sources

Replace the default overseas mirrors with a domestic mirror (e.g., USTC) for faster downloads.

6.1.1 Edit /etc/apt/sources.list

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

6.1.2 Edit /etc/apt/sources.list.d/raspi.list

sudo nano /etc/apt/sources.list.d/raspi.list
# comment out existing lines and add:
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main ui

6.1.3 Update packages

sudo apt-get update
sudo apt-get upgrade

6.2 Set timezone

sudo dpkg-reconfigure tzdata

Select “Asia → Shanghai”.

6.3 Enable SSH on boot

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

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

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

Visit http://<strong>192.168.0.104</strong> (replace with your Pi’s IP) in a browser to see the default Nginx page.

In‑network Penetration

To expose the internal web service to the public, use tools like ngrok or frp. The author tried several free Chinese ngrok services; the ngrok_arm binary works on the Zero W.

Run ngrok in a screen session for background execution, though automatic startup is not yet implemented.

More

The Raspberry Pi can do far more than host a website; explore the Raspberry Pi Lab for additional tutorials and projects.

Current status: Nginx and ngrok are running, ~250 MB RAM free, CPU temperature stable around 37‑39 °C after two days of operation.

Zero W size comparison
Zero W size comparison
NetworkLinuxNginxraspberry-piSSHSystem SetupZero W
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

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.