Ramblings of an aging IT geek
← Ramblings of an aging IT geek
homelab

nextcloud, again, properly this time

A second attempt at self-hosting Nextcloud, this time with a separate database, Redis, and a reverse proxy instead of the all-in-one image.

A homelab setup with cabling and disks

I've run Nextcloud before. It was slow, the file scans crawled, and the admin overview page glared at me with warnings I'd learned to ignore. So I took it down, sulked for a few months, and convinced myself the hosted options were fine. They're fine. They're also not mine, and the point of all this is that it's mine.

So: Nextcloud again, properly this time. The mistake last time was the single all-in-one container with SQLite quietly underneath. It works for a demo and falls over the moment you actually use it.

the layout that worked

This time I split the pieces. PostgreSQL for the database, Redis for file locking and caching, and the Nextcloud FPM image behind nginx rather than the bundled Apache. Each in its own container, on a compose stack, with the data on a dedicated dataset rather than tangled up in the app volume.

services:
  db:
    image: postgres:13
    environment:
      POSTGRES_DB: nextcloud
    volumes:
      - ./pgdata:/var/lib/postgresql/data
  redis:
    image: redis:6-alpine
  app:
    image: nextcloud:21-fpm
    depends_on:
      - db
      - redis

A homelab rack and disks

Nextcloud 21 landed last month and the transactional file locking via Redis is the bit that quietly fixed everything. Before, two clients syncing at once produced lock warnings and the occasional sulk. With Redis doing the locking, that noise just stopped.

the bits that always bite

Two things still caught me out, the same two that catch everyone:

  • Trusted domains. The reverse proxy means Nextcloud sees a different host and protocol than the browser does. You have to tell it, via trusted_proxies and overwrite.cli.url in config.php, or every link comes out as http on the wrong hostname.
  • PHP memory and opcache. The defaults are too low. Bump memory_limit to 512M and turn opcache on properly, or the admin page will keep nagging and the UI will feel like wading through treacle.

After that, the overview page went green. All of it. I genuinely stared at it for a moment because I'd never actually seen it without a warning before.

Is it perfect? No. The Android client still occasionally decides a photo needs re-uploading for reasons known only to itself. But it's fast now, it's backed by a real database, and the backups are a pg_dump plus a snapshot of one dataset rather than a prayer. That's the difference between a toy and a thing you trust your photos to.

If you tried Nextcloud once, hated it, and walked away: it was probably the all-in-one image. Split it up and try again. It's a different piece of software when you do.