Nextcloud turns a cheap VPS into your own file cloud: file sync across devices, calendar, contacts, notes, and photo backup — without a monthly per-GB bill. This guide uses Docker Compose, which is the least painful way to run and keep it updated.
Why self-host Nextcloud instead of using Google Drive?
Three reasons people make the switch:
- You own the data. It lives on a server you control, not in someone else’s account that can be suspended or scanned.
- No per-GB subscription. You pay only for the VPS. Storing 500 GB costs the same as storing 5 GB until the disk fills up.
- It’s more than storage. Nextcloud also does calendar, contacts, notes, and phone photo backup — a small private cloud, not just a drive.
The trade-off is honest: you maintain it. That’s updates, backups, and the occasional bit of troubleshooting. This guide is built so that trade-off stays small.
Prerequisites
- A VPS with 2 GB RAM or more (see which VPS to pick), running a recent Ubuntu/Debian.
- A domain (e.g.
cloud.yourdomain.com) pointed at the server — see how to point a domain to a VPS. - Docker + Docker Compose installed.
Step 1 — Create the Compose file
Create a folder and a docker-compose.yml:
services:
db:
image: mariadb:11
restart: always
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
volumes:
- db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: change_me_root
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: change_me
app:
image: nextcloud:stable
restart: always
ports:
- "8080:80"
depends_on:
- db
volumes:
- nextcloud:/var/www/html
environment:
MYSQL_HOST: db
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: change_me
NEXTCLOUD_ADMIN_USER: admin
NEXTCLOUD_ADMIN_PASSWORD: change_me_admin
NEXTCLOUD_TRUSTED_DOMAINS: cloud.yourdomain.com
volumes:
db:
nextcloud:
Change every change_me* value and set NEXTCLOUD_TRUSTED_DOMAINS to your real subdomain. The two named volumes (db, nextcloud) are where your data lives — remember them, because they’re what you back up later.
Step 2 — Start it
docker compose up -d
docker compose logs -f app # watch until it's ready
Nextcloud is now listening on port 8080 on the server — but only locally; it’s not safely public yet.
Step 3 — Add HTTPS with a reverse proxy
Don’t expose port 8080 directly. Put Nginx Proxy Manager in front, point cloud.yourdomain.com → http://app:80 (or the host’s :8080), and let it issue a free Let’s Encrypt certificate. Full walkthrough: Nginx Proxy Manager setup.
This is the step that turns “running on a port” into “a real, encrypted site you can log into from your phone.”
Step 4 — First-run setup
Open https://cloud.yourdomain.com, log in with the admin user you set, and install the apps you want (Calendar, Contacts, Notes, Photos). For better performance with several users, add Redis for file locking — but the stack above is fine to start.
Step 5 — Back it up (don’t skip this)
A self-hosted cloud you can’t restore is a liability. Back up two things:
- The data volume (
nextcloud) — your actual files. - The database — a
mysqldumpof thenextclouddatabase.
The simplest reliable setup is a nightly cron job that dumps the database and syncs both to off-site object storage like Backblaze B2 or S3. Keeping backups on the same server defeats the purpose — if the box dies, so do they.
Troubleshooting
- “Access through untrusted domain” — your domain isn’t in
NEXTCLOUD_TRUSTED_DOMAINS. Fix the value and rundocker compose up -dagain. - 502 / bad gateway from the proxy — the proxy is pointing at the wrong container name or port. It should target the app container on port
80. - Uploads of large files fail — raise the proxy’s
client_max_body_sizeand PHP upload limits; the default caps are low. - Slow first load — small boxes benefit from adding Redis for caching and file locking once you have a few users.
Which VPS to run it on
Nextcloud is light for one person but disk-hungry once you sync photos. A 2 GB managed instance on Cloudways is the hands-off option; a cheap Hetzner box is the best value if you’re comfortable on the CLI. Full comparison: Best VPS for Self-Hosting. For low-latency access from mainland China, see the BandwagonHost HK review.
Once Nextcloud is running, the same VPS can host more: a password manager (Vaultwarden) or a Google Photos replacement (Immich) sit happily alongside it.