Securing Nextcloud, area by area
Start with the scan and the Overview page
Nextcloud's free scan at scan.nextcloud.com checks any public server against the known vulnerabilities for its version and the hardening it can see from outside. It rates the result:
A+: up to date, well configured and with the latest hardening features.
A: no known vulnerabilities, but newer versions offer more hardening.
C, D and E: at least one known vulnerability rated low, medium or high.
F: end of life, with no security fixes.
The scan cannot see inside the server, so backups, sign-in rules and file permissions are beyond it, and it is a snapshot in time. Inside, Nextcloud runs its own configuration checks and lists any warnings on the Overview page of the administration settings. Clear every one.
Stay on a supported version
Every major version gets security fixes for one year, delivered in maintenance releases about every four weeks. Nextcloud's admin manual says to install maintenance releases as soon as possible and calls running an actively maintained major version critical. Check your version against Nextcloud's published support dates and plan each major upgrade before its end date, not after.
Lock down the connection
Serve Nextcloud only over HTTPS, and send all plain HTTP traffic to HTTPS with a permanent 301 redirect. Add the HTTP Strict Transport Security header so browsers refuse plain connections; Nextcloud warns if it is set for less than 15552000 seconds, which is 180 days. For the TLS settings themselves, the manual points to the Mozilla SSL Configuration Generator, with Qualys SSL Labs to check the result.
Install Nextcloud on its own domain, such as cloud.example.org, rather than in a folder of your main website, so the browser's same-origin protections keep the two apart.
Protect sign-in
Nextcloud ships with two-factor options for authenticator apps (TOTP), for approval from a signed-in device and for backup codes, but each user decides whether to use them until an administrator enforces it. Enforce it under Administration settings, then Security, for everyone or at least for admin groups. Backup codes, ten per user and each usable once, get people back in when a phone is lost. If you use single sign-on, enforce the second factor at your sign-in provider.
Brute-force protection is on by default and slows repeated failed sign-ins from the same IP address. Leave it on. If Nextcloud sits behind a reverse proxy, set trusted_proxies correctly, or the protection cannot tell your users' addresses apart. The manual's fail2ban recipe goes further and blocks repeat offenders at the operating system level. Add the Password policy app to set a minimum length and other rules.
Limit admin access
Set allowed_admin_ranges in config.php to the IP ranges your administrators work from. Admins connecting from anywhere else can still use Nextcloud, but admin settings are hidden from them. Keep the admin group small, and give administrators a separate everyday account for their own files and sharing. Brute-force settings also sit under Administration settings, then Security, where you can exempt trusted address ranges. Exempt as little as possible: the manual prefers fixing the cause of false alarms, such as a misconfigured reverse proxy.
Control sharing
Under Administration settings, then Sharing, you can require a password on every link share and set default and enforced expiration dates, separately for internal shares and for link and email shares. Turn both on for links that leave the organization. The File access control app adds rules that deny access by IP address, user group, tag and more, for example blocking a team's files outside working hours. Then review the link shares that already exist, especially on sensitive folders, and remove the ones nobody needs.
Harden the server underneath
Keep the data directory outside the web root, ideally from installation. Leave debug mode off in config.php. Make sure PHP can read /dev/urandom, and use a hardening module such as SELinux where you can. Nextcloud connects to other servers by design, for federation and external storage, so the manual advises a segregated network with firewall rules if it must not reach your internal hosts. Keep the operating system, PHP and database patched as well; Nextcloud drops PHP versions as they age.
Pick encryption for the threat
Nextcloud offers several kinds, and they are not interchangeable. Server-side encryption mainly protects files on external storage such as S3; it does not encrypt file names and does not protect against a compromised server or administrator. End-to-end encryption, set on chosen folders, keeps files unreadable on the server itself. Disk encryption, such as LUKS, protects against a stolen disk or server. Whichever you choose, losing the keys means losing the data, so back them up.
Keep records, backups and an eye on apps
Turn on the admin_audit app for a record of who opened, shared or deleted what, readable under Administration settings, then Logging, when you log to a file. Back up the config, data and theme folders and the database to a separate location, and test a restore. Remove apps nobody uses, and review third-party apps, marked "3rd party" in the app list, which you install at your own risk. If people upload files from outside, the Antivirus for files app can scan uploads with ClamAV.
Watch for trouble
Nextcloud records failed sign-ins in nextcloud.log at log level 2, so keep the log level at 2 or lower in production; fail2ban depends on those entries. Watch certificate expiry dates and free disk space, because an expired certificate or a full disk breaks sync. From Nextcloud 33, a /metrics endpoint feeds monitoring tools such as Prometheus. It answers only on the server itself by default, and the manual warns not to open it to everyone.