Nextcloud is an open-source alternative to Dropbox, Google Drive and Microsoft 365’s file features: file sync across devices, sharing links, calendars, contacts, document editing and video calls — all on your own server. For businesses that must keep data in a particular jurisdiction, or teams that collaborate between mainland China and the rest of the world (where some international cloud services are unreliable), a self-hosted Nextcloud in Hong Kong, Japan or Singapore is a practical solution.
Planning
| Users | CPU / RAM | Storage |
|---|---|---|
| 1–10 | 2 vCPU / 4 GB | As much as your files need, plus room to grow |
| 10–50 | 4 cores / 8 GB | Fast SSD/NVMe for the database; large disk for data |
| 50+ | Dedicated server, 8+ cores / 16 GB+ | Consider separate storage, backups to another location |
Storage is usually the deciding factor. A dedicated server with large disks is often cheaper per terabyte than cloud storage for sustained use.
You need a domain or subdomain (cloud.example.com) pointing to the server, and ports 80/443 open.
Option 1: Nextcloud All-in-One (easiest)
Nextcloud AIO is the officially recommended Docker installation. One “master” container sets up and maintains everything else: Nextcloud, database, Redis, HTTPS, backups, Collabora/OnlyOffice and Talk.
sudo docker run -d \
--init \
--sig-proxy=false \
--name nextcloud-aio-mastercontainer \
--restart always \
--publish 80:80 \
--publish 8080:8080 \
--publish 8443:8443 \
--volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
nextcloud/all-in-one:latest
Open https://YOUR_SERVER_IP:8080 (accept the self-signed certificate), note the passphrase shown, enter your domain, and AIO deploys the rest. Close port 8080 to the public afterwards or restrict it to your IP.
AIO is the best choice if you want minimal maintenance. If you prefer to control each component, use Option 2.
Option 2: Docker Compose with MariaDB and Redis
sudo mkdir -p /srv/nextcloud && cd /srv/nextcloud
.env:
MYSQL_ROOT_PASSWORD=change-me-root
MYSQL_PASSWORD=change-me-nextcloud
compose.yaml:
services:
db:
image: mariadb:11.4
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
volumes:
- db:/var/lib/mysql
redis:
image: redis:7-alpine
restart: unless-stopped
app:
image: nextcloud:30-apache
restart: unless-stopped
ports:
- "127.0.0.1:8081:80"
environment:
MYSQL_HOST: db
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
REDIS_HOST: redis
NEXTCLOUD_TRUSTED_DOMAINS: cloud.example.com
OVERWRITEPROTOCOL: https
TRUSTED_PROXIES: 172.16.0.0/12
PHP_UPLOAD_LIMIT: 10G
PHP_MEMORY_LIMIT: 1G
volumes:
- nextcloud:/var/www/html
- /data/nextcloud:/var/www/html/data
depends_on: [db, redis]
cron:
image: nextcloud:30-apache
restart: unless-stopped
entrypoint: /cron.sh
volumes:
- nextcloud:/var/www/html
- /data/nextcloud:/var/www/html/data
depends_on: [db, redis]
volumes:
db:
nextcloud:
Use the current stable major version tag for nextcloud: and upgrade one major version at a time.
sudo mkdir -p /data/nextcloud && sudo chown 33:33 /data/nextcloud # www-data in the image
docker compose up -d
Reverse proxy with HTTPS
On the host, Nginx in front of port 8081 (see Nginx and Let’s Encrypt):
server {
listen 443 ssl;
http2 on;
server_name cloud.example.com;
# ssl_certificate lines added by certbot
client_max_body_size 10G;
client_body_timeout 300s;
proxy_request_buffering off;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 300s;
}
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
}
Open https://cloud.example.com, create the admin account, and skip installing recommended apps until the basics work.
After installation
Use occ, Nextcloud’s command-line tool:
docker compose exec -u www-data app php occ status
docker compose exec -u www-data app php occ background:cron # use the cron container
docker compose exec -u www-data app php occ db:add-missing-indices
docker compose exec -u www-data app php occ maintenance:repair --include-expensive
docker compose exec -u www-data app php occ config:system:set default_phone_region --value="HK"
docker compose exec -u www-data app php occ config:system:set maintenance_window_start --type=integer --value=19
Then check Administration settings → Overview. Nextcloud lists configuration warnings there; work through them until the list is clear.
Performance
- Redis for file locking and caching (configured above via
REDIS_HOST). - APCu local cache is enabled in the official image.
- Database on SSD/NVMe.
- PHP memory limit 512 MB–1 GB.
- For large installations, preview generation is a major CPU consumer — install the Preview Generator app and generate previews from cron instead of on demand.
Clients
Desktop sync clients exist for Windows, macOS and Linux, and mobile apps for iOS and Android. Calendars and contacts sync via CalDAV/CardDAV with phones and Thunderbird. Collaborative editing of Office documents is available through Nextcloud Office (Collabora) or OnlyOffice.
Security
- Two-factor authentication for all users (TOTP app, available in the app store).
- Brute-force protection is built in; make sure the real client IP reaches Nextcloud (
TRUSTED_PROXIES), or all users share one “IP”. - Enable server-side encryption only if you understand the trade-offs (it protects against external storage providers, not against a compromised server, and complicates recovery).
- Keep Nextcloud and apps updated; disable apps you do not use.
- Run the Nextcloud security scan at scan.nextcloud.com against your instance.
Backups
Back up three things, ideally while Nextcloud is in maintenance mode:
docker compose exec -u www-data app php occ maintenance:mode --on
docker compose exec -T db mariadb-dump -u root -p"$MYSQL_ROOT_PASSWORD" --single-transaction nextcloud | gzip > /var/backups/nextcloud-db-$(date +%F).sql.gz
# data directory (/data/nextcloud) and config (inside the nextcloud volume: config/config.php)
docker compose exec -u www-data app php occ maintenance:mode --off
Copy data to another server or location with restic or rsync. Nextcloud AIO includes its own BorgBackup-based backup feature.
Updating
Upgrade one major version at a time (29 → 30 → 31). With Compose, change the image tag, docker compose pull, docker compose up -d, and watch the logs while the upgrade runs. AIO handles updates from its interface.