Untrusted domain error but only happens when going through nginx reverse proxy

Nextcloud version (eg, 12.0.2): 18.0.3
Operating system and version (eg, Ubuntu 17.04): FreeBSD 12.1
Apache or nginx version (eg, Apache 2.4.25): nginx 1.16
PHP version (eg, 7.1): 7.4

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Browse to nextcloud instance while going through reverse proxy providing SSL

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):
`<?php
$CONFIG = array (
‘apps_paths’ =>
array (
0 =>
array (
‘path’ => ‘/usr/local/www/nextcloud/apps’,
‘url’ => ‘/apps’,
‘writable’ => true,
),
1 =>
array (
‘path’ => ‘/usr/local/www/nextcloud/apps-pkg’,
‘url’ => ‘/apps-pkg’,
‘writable’ => false,
),
),
‘logfile’ => ‘/var/log/nextcloud/nextcloud.log’,
‘memcache.local’ => ‘\OC\Memcache\APCu’,
‘instanceid’ => ‘ocb6qogvesyu’,
‘passwordsalt’ => ‘’,
‘secret’ => ‘’,
‘trusted_domains’ =>
array (
0 => ‘mydomain.com’,
1 => ‘192.168.1.106’, ),
‘datadirectory’ => ‘/usr/local/www/nextcloud/data’,
‘dbtype’ => ‘mysql’,
‘version’ => ‘18.0.3.0’,
‘dbname’ => ‘nextcloud’,
‘dbhost’ => ‘localhost’,
‘dbport’ => ‘’,
‘dbtableprefix’ => ‘oc_’,
‘mysql.utf8mb4’ => true,
‘dbuser’ => ‘nextcloud’,
‘dbpassword’ => ‘’,
‘installed’ => true,
#‘overwrite.cli.url’ => ‘https://mydomain.com’,
);

I installed nextcloud and was able to access it directly with the DNS record set to the host itself. I only have http configured on the nextcloud instance because I use an nginx reverse proxy to provide SSL for multiple servers.

Everything was working when accessing nextcloud directly but now that I have changed the DNS record to the reverse proxy I get the untrusted domain error but the domain is the same as it was when accessing it directly so I don’t know what’s causing it. I can also access it directly by the IP address.

Is there a way to disable the check entirely? I wouldn’t mind losing that security because the reverse proxy is handling that anyway.

Thanks in advance.

For anyone stumbling across this I had to add the following to the location section of the reverse proxy.

                    proxy_set_header Host $host;
                    proxy_set_header X-Forwarded-Proto $scheme;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                    add_header Front-End-Https on;

I also needed to add the trusted_proxies variable to config.php on nextcloud

1 Like