NOC online · 24/7Longview, TX · +1 323 412 0665
KinetikatechServers · Security · Websites
ES

Esta guía detallada está disponible en inglés.

English version

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.

Puntos clave

  1. Move from SQLite to PostgreSQL before scaling. SQLite serializes writes and becomes the bottleneck long before user count does.
  2. 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.
  3. 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.
  4. Enable file locking with Redis. The default database locking creates row contention on every upload and sync.
  5. Offload background jobs. Run occ background:ajax or a cron worker on a dedicated node so heavy maintenance does not block user requests.
  6. Index the database deliberately. Add indexes for oc_filecache and oc_share introduced by your actual query patterns, not the default set.
  7. Cache aggressively at the edge. Put a reverse proxy with long-lived cache headers in front of static assets and thumbnails.
  8. 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

PHP-FPM pool tuning ini
; /etc/php/8.3/fpm/pool.d/nextcloud.conf
pm = static
pm.max_children = 64
pm.start_servers = 64
pm.min_spare_servers = 64
pm.max_spare_servers = 64
pm.max_requests = 500
php_admin_value[memory_limit] = 512M
php_admin_value[opcache.enable] = 1
php_admin_value[opcache.memory_consumption] = 256
Nextcloud config.php cache and locking php
'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => [
  'host' => '127.0.0.1',
  'port' => 6379,
  'timeout' => 0.0,
  'password' => '',
  'dbindex' => 0,
],
'dbtype' => 'pgsql',
'dbhost' => '127.0.0.1',
'dbname' => 'nextcloud',
'dbuser' => 'nextcloud',
'dbpassword' => 'change-me'
Background job cron bash
*/5 * * * * www-data php /var/www/nextcloud/cron.php
# or, for ajax mode safety:
sudo -u www-data php /var/www/nextcloud/occ background:cron

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.

Preguntas frecuentes

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.

Cómo ayuda Kinetikatech con self-hosted open source infrastructure

Seamos honestos, la mayoría de los equipos llegan después de intentarlo por su cuenta: Running sovereign collaboration, storage, and identity stacks on hardware you control. Nuestro servicio Gestión de servidores y Mantenimiento web existe para que no tenga que aprender self-hosted open source infrastructure por las malas: nos encargamos de la configuración, la vigilancia y las sorpresas de las 3 a. m.

Hablar con un ingeniero

¿Problemas con el servidor? ¿Sitio hackeado? ¿Web lenta?

Incidencias críticas atendidas en 30 minutos — 24 horas al día, 7 días a la semana.

Solicitar soporte urgente support@kinetikatech.com