Self-Hosted Open Source Infrastructure
Scaling Self-Hosted Nextcloud to 5,000 Users
Nextcloud works fine for a team and then falls over when the whole company arrives. The failure is rarely the web server. It is database lock contention, Redis cache stampedes, file locking overhead, and background job queues that cannot keep up. This guide scales a self-hosted Nextcloud instance to several thousand users with PostgreSQL, Redis, and a tuned PHP-FPM pool.
要点
- Move from SQLite to PostgreSQL before scaling. SQLite serializes writes and becomes the bottleneck long before user count does.
- Separate Redis roles. Use one instance for locking, one for caching, and one for session storage, or at least separate databases with distinct eviction policies.
- Tune PHP-FPM for steady state. Set pm to static with a worker count derived from available memory, not dynamic, which thrashes under bursty load.
- Enable file locking with Redis. The default database locking creates row contention on every upload and sync.
- Offload background jobs. Run occ background:ajax or a cron worker on a dedicated node so heavy maintenance does not block user requests.
- Index the database deliberately. Add indexes for oc_filecache and oc_share introduced by your actual query patterns, not the default set.
- Cache aggressively at the edge. Put a reverse proxy with long-lived cache headers in front of static assets and thumbnails.
- Measure before tuning. Use the built-in server info endpoint and database slow query logs to find the actual bottleneck.
Architecture
The request path runs from the edge proxy through PHP-FPM into PostgreSQL for metadata and Redis for locking and cache. Background jobs and previews run out of band. Scaling means keeping the database off the hot path for reads, which is why Redis carries cache and lock state while PostgreSQL holds the durable record.
Production configuration
Edge cases from production
- Large file uploads fail when client_max_body_size and PHP upload limits disagree; set both to the same value and test with a real large file.
- Redis eviction under memory pressure drops locks and corrupts uploads; set maxmemory-policy to noeviction for the locking instance.
- Federation shares across instances require matching protocol versions; mismatched versions silently fail.
- Previews for video and office documents consume CPU; disable preview generation for file types you do not need.
よくある質問
How many users can one Nextcloud node serve?
A well-tuned single node with PostgreSQL and Redis handles a few thousand active users; beyond that, split the database and add app servers behind a load balancer.
Should I use MariaDB or PostgreSQL?
PostgreSQL handles concurrent writes and large filecache tables better at scale; MariaDB is simpler for small deployments.
Why are file listings slow?
Usually a missing index on oc_filecache or an undersized Redis cache; check slow queries before adding hardware.
How do I handle a Redis failover?
Use Redis Sentinel or a managed service and configure Nextcloud to connect through the sentinel; test failover during a maintenance window.
Is object storage worth it?
Yes once file volume exceeds local disk comfort; S3-compatible storage offloads the primary disks and simplifies backups.
self-hosted open source infrastructure に対するKinetikatechの支援
self-hosted open source infrastructure の専門家になる必要はありません:Running sovereign collaboration, storage, and identity stacks on hardware you control. それがまさにサーバー管理とWebサイト保守が存在する理由です。セットアップ、強化、監視、そして昼夜を問わず駆けつける人間のサポート。