DEV Community

Daniele Michelin
Daniele Michelin

Posted on Originally published at daniele-michelin.com

Nextcloud "access through untrusted domain": fix

Nextcloud was opened via a hostname or IP that is not listed in trusted_domains, so it refuses to log you in.

Common causes

  • A new hostname after a domain change or migration that was never added.
  • Access directly via the IP address or an internal name.
  • The reverse proxy forwards a different Host header than the public name.
  • Docker: NEXTCLOUD_TRUSTED_DOMAINS is only applied on the first install.

How to check it

Show configured trusted domains

sudo -u www-data php /var/www/nextcloud/occ config:system:get trusted_domains
Enter fullscreen mode Exit fullscreen mode

Check proxy-related settings

grep -nE 'trusted_proxies|overwritehost|overwriteprotocol|overwrite.cli.url' /var/www/nextcloud/config/config.php
Enter fullscreen mode Exit fullscreen mode

Test the backend directly with a Host header

curl -s -o /dev/null -w '%{http_code}\n' -H 'Host: cloud.example.com' http://127.0.0.1/status.php
Enter fullscreen mode Exit fullscreen mode

What actually helps

  1. Add the domain (use the next free index): sudo -u www-data php occ config:system:set trusted_domains 1 --value=cloud.example.com.
  2. Forward the original host in the reverse proxy: proxy_set_header Host $host;.
  3. Behind a proxy set trusted_proxies and, if needed, overwritehost and overwriteprotocol.

FAQ

Can I allow every domain with *?

Wildcards like *.example.com work, a bare * makes no sense. The list protects against host header attacks such as manipulated password reset links.

Do I need to restart anything after the change?

No. Nextcloud reads config.php on every request, so the change applies immediately.


Full page with every command and the German/Italian version: daniele-michelin.com/en/errors/nextcloud-trusted-domain-error/

First published at daniele-michelin.com. The error lexicon covers HTTP, DNS, TLS, mail, database, PHP, nginx, systemd and Nextcloud, in German, English and Italian.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

This is the kind of post I wish existed the first time I hit this error, Daniele — the message sounds like a login problem, but it is really a hostname allowlist problem, and your "check it" section is the fastest way to prove which side is wrong. The Docker detail is the one that would have saved me the most time: NEXTCLOUD_TRUSTED_DOMAINS only applying on first install means editing the environment and restarting changes nothing, and it is easy to blame the proxy instead. The curl test with the Host header is a neat next step because it separates a proxy problem from a Nextcloud config problem in one command. In your support work, which cause do you see most often — the proxy forwarding a different Host header, or a domain change that was never added to trusted_domains?