Tutorial

How to Self-Host a NAS and Private Cloud with Nextcloud

Why this matters

Cloud storage is convenient until you hit the limit, or until you realize a corporation holds your files and can change the price or the rules. A self-hosted NAS gives you your own storage, on your hardware, with no monthly fee and no size limit except the disks you buy.

Nextcloud adds the “cloud” layer on top — file sync, calendar, contacts, and a web UI.

What I tested on

  • OS: Debian 13 (trixie)
  • Nextcloud: 29.x (AIO)
  • Samba: 4.19.x
  • Hardware: 4-bay NAS with 8 TB usable (ZFS mirror), 16 GB RAM
  • Duration: Nextcloud for 10 months, Samba for 3 years

⚠️ RAID is not a backup. A mirror protects against one disk failing; it does not protect against fire, theft, accidental deletion, or ransomware. Keep an offsite copy.

How I tested

I copied a real multi-device workflow onto it — photos from a phone, documents from a laptop, and a shared family folder — and used it as the only sync method for a month. The friction points I hit are what I’m documenting here.

Step 1: The storage layer (ZFS)

For a real NAS, use ZFS:

# Create a mirrored pool
zpool create tank mirror /dev/sdb /dev/sdc

# Create a dataset
zfs create tank/data
zfs set compression=lz4 tank/data

ZFS gives you checksums, compression, and the ability to spot corrupted data — which matters more than speed for a file server.

Step 2: Samba for network shares

# /etc/samba/smb.conf
[tank]
   path = /tank/data
   browseable = yes
   read only = no
   valid users = @sambashare
sudo smbpasswd -a youruser
sudo systemctl restart smbd

This is the “just a share” route — no cloud features, just files on the network. It’s often all you need.

Step 3: Nextcloud AIO with Docker

docker run \
  -d \
  --name nextcloud-aio-mastercontainer \
  --restart always \
  -p 8080:8080 \
  -e NEXTCLOUD_DATADIR="/tank/nextcloud" \
  -v nextcloud_aio_mastercontainer:/mnt/docker-aio \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  nextcloud/all-in-one:latest

Open port 8080, walk through the browser setup, and AIO provisions everything — database, Redis, Collabora, and the main app. It’s the least painful way to get a full private cloud running.

Step 4: Backups

ZFS snapshots are fast and cheap:

zfs snapshot tank/data@daily
zfs send tank/data@daily | ssh backup-host zfs receive backup/data

Snapshots protect against accidental deletion; zfs send to another machine protects against disk failure.

Four settings that fixed my upload speed

Nextcloud is not slow by nature, but the default stack is tuned for compatibility rather than throughput. Four changes took my uploads from 3 MB/s to near line rate on the same hardware.

Redis for file locking. Without a shared lock backend, Nextcloud falls back to database locking and concurrent uploads serialise. One Redis container, one config line, and the “file is locked” errors stop.

PHP-FPM workers sized to the box. The default pool is small; a NAS with four cores and 4 GB should run more than five children, and a container with two cores should not run twenty. Watch memory, not CPU — PHP workers are the usual cause of an AIO container getting OOM-killed.

APACHE_BODY_LIMIT / upload limits aligned. The web server, PHP and the reverse proxy each have a maximum body size. If any one of them is 512 MB while the others are 10 GB, a large upload fails with a client error that points at none of them.

Chunked uploads through the proxy. Nextcloud splits large files into chunks, and a proxy that buffers or times out mid-chunk produces partial uploads. If you front it with a proxy, raise the read timeout rather than disabling chunking — the Caddy walkthrough has the config shape.

The honest caveat: a spinning disk array will still bottleneck a 40 GB upload. Tuning gets you to the disk, not past it.

Backing up a service with a database

Files plus a database means you cannot simply copy the data directory while it is running. The order matters, and Nextcloud’s own maintenance mode exists for exactly this.

# 1. stop writes
docker exec -u www-data nextcloud-aio-mastercontainer php occ maintenance:mode --on

# 2. database dump
docker exec nextcloud-aio-database pg_dump -U nextcloud nextcloud > nextcloud.sql

# 3. files (rsync is fine here, writes are paused)
rsync -a --delete /mnt/ncdata/ /backup/ncdata/

# 4. back to normal
docker exec -u www-data nextcloud-aio-mastercontainer php occ maintenance:mode --off

Do not skip step 2. Restoring a file tree without the matching database gives you a Nextcloud that starts and shows an empty user list — which looks like data loss and is actually a schema mismatch.

Test the restore into a separate container once, then schedule it. The generic routine, including retention and the offsite copy, is in the backup guide; this is just the service-specific wrapper around it.

Pros and cons

Pros:

  • Your files live on your hardware, fully under your control
  • Nextcloud gives you sync, sharing, calendar, and contacts in one app
  • No recurring storage fee — disk is a one-time cost
  • Can replace several paid cloud subscriptions

Cons:

  • Setup is more involved than a USB disk
  • You maintain the hardware and the software
  • Nextcloud AIO is resource-heavy (2+ GB RAM, several containers)
  • Remote access requires careful setup (reverse proxy + auth)

Best for / Skip if

Best for: anyone with more than one device, or who wants a private alternative to Google Drive / Dropbox / iCloud.

Skip if: you just need to move files between two computers. A USB disk and Samba are enough.

Alternatives

  • Samba / NFS only — just a network share; no sync client, no web UI
  • Syncthing — peer-to-peer sync, no server, excellent for two or three devices
  • TrueNAS — a full NAS OS with a web UI; heavier but very complete

Verdict

A self-hosted NAS is the foundation of a homelab because everything else — backups, media, files — sits on top of it. Samba alone is enough for simple sharing; Nextcloud is worth the extra complexity once you want sync across phones and laptops. Start with the share, add Nextcloud when you miss the cloud features.

References

FAQ

How much RAM does Nextcloud AIO need?

2 GB minimum, 4 GB comfortable. It runs several containers.

Is RAID enough?

No. RAID protects against disk failure only. You still need offsite and snapshots.

Can I access files remotely?

Yes, via Nextcloud's web UI behind a reverse proxy with HTTPS, or a VPN.

Should I encrypt the disks?

If the server lives anywhere someone could walk in and take it, yes — LUKS or ZFS native encryption.

Henry Xiang

I keep self-hosted services alive for a living — backups, docs, monitoring, the boring parts that break at 3am. Everything here runs on my own hardware first.