Cara menggunakan nextcloud config.php trusted domains

Nextcloud is one of the most powerful and flexible locally hosted cloud servers. But what happens when it won't let you log in, because of a Trusted Domain issue? Jack Wallen shows you what to do.

Cara menggunakan nextcloud config.php trusted domains

I have, on a number of occasions, run into an issue where I am unable to log into an instance of Nextcloud because the server hosting the service changed the IP address. When this happens, the trusted domain issue appears, and there’s no way (without a quick re-configure) to log in.

Networking: Must-read coverage

  • NVIDIA unveils supercomputing and edge products at SC22
  • Get instant malware filtering with Gryphon Guardian
  • How industrial IoT is forcing IT to rethink networks
  • How to configure networking on a Linux server (TechRepublic Premium)

What is a trust domain? For Nextcloud, a trusted domain is a way to prevent Host Header Poisoning.

See: Network security policy (Tech Pro Research)

What is Host Header Poisoning? In most cases, developers trust an HTTP Host header value and use it to do things like generate links, import scripts, and even generate password resets. The problem is that the HTTP Host header can be controlled by an attacker and exploited using web-cache poisoning and/or abusing alternative channels like password reset emails. Because of this, the Nextcloud developers added the trusted domain feature. So, if you do something like move your Nextcloud server to a different IP address, you’ll see the feature in action. In other words, you won’t be able to log in.

What do you do?

You configure a new trusted domain. I’m going to show you how. I’ll demonstrate on Nextcloud 13 hosted on Ubuntu 18.04. I will assume you’ve installed Nextcloud into the /var/www/html/nextcloud directory.

Adding a new trusted domain

Log into (or Secure Shell into) your server hosting Nextcloud. Open the necessary configuration file with the command:

sudo nano /var/www/html/nextcloud/config/config.php

In that file, you should see the line:

0 => IP_1

Where IP_1 is the original IP address of your Nextcloud server.

Add a new line below, like so:

1 => IP_2

Where IP_2 is the new IP address of the Nextcloud server.

The end result should have both old and new IP addresses listed (Figure A).

Figure A

Cara menggunakan nextcloud config.php trusted domains

NOTE: If you installed Nextcloud via snap packages, the configuration file will be found in the /var/snap/nextcloud/current/nextcloud/config directory.

Ready to log in

After you save and close the config.php file, you should now be able to go back to your Nextcloud instance without the Trusted Domain issue preventing logins. There’s no need to restart Nextcloud or the hosting server. That’s all there is to resolving this particular issue. Just remember, if you change the IP address of your server again, you’ll need to add the new address to the config.php file.

Your Nextcloud server is back and ready to work.

Cara menggunakan nextcloud config.php trusted domains

Daily Tech Insider Newsletter

Stay up to date on the latest in technology with Daily Tech Insider. We bring you news on industry-leading companies, products, and people, as well as highlighted articles, downloads, and top resources. You’ll receive primers on hot tech topics that will help you stay ahead of the game.

this is where i’m at . .
trying theming for domains

CONFIG.PHP

 '---',
  'passwordsalt' => '--',
  'secret' => '---',
  'trusted_domains' => 
  array (
   0 => 'localhost',
   1 => 'domain0.net',
   2 => '111.222.333.44',
   4 => 'domain1.net',
   ),
   . . .

DOMAINS.CONFIG.PHP

 'domain0.net',
    1 => 'domain1.net'
);
if (isset($_SERVER['HTTP_HOST'])) {
    switch ($_SERVER['HTTP_HOST']) {
        case 'domain0.net':
            $CONFIG['theme']='domain0.net';
            $CONFIG['mail_from_address'] = 'address';
            $CONFIG['mail_domain'] = 'domain0.net';
            break;
        case 'domain1.net':
            $CONFIG['theme']='domain1.net';
            $CONFIG['mail_from_address'] = 'address';
            $CONFIG['mail_domain'] = 'domain1.net';
            break;
    }
}

somebody with experience in this matter?

Hi @Mageunic,

I tried revert the changes on config.php for redis but still have this issue.
All the logs seems to be yesterdays log, any changes made today did not reflect on the logs.
Please refer below for logs.

{"reqId":"nrNFo5EuLxNqUUqtDkWb","level":3,"time":"2021-03-29T03:48:04+00:00","remoteAddr":"192.168.10.92","user":"Hakim","app":"no app in context","method":"POST","url":"/index.php/settings/apps/enable","message":{"Exception":"Error","Message":"Call to a member function getContainer() on null","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":143,"function":"delegateContainerRegistrations","class":"OC\\AppFramework\\Bootstrap\\RegistrationContext","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":86,"function":"registerApps","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/lib/private/Installer.php","line":146,"function":"runLazyRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/apps/settings/lib/Controller/AppSettingsController.php","line":448,"function":"installApp","class":"OC\\Installer","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":218,"function":"enableApps","class":"OCA\\Settings\\Controller\\AppSettingsController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":127,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":993,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/RegistrationContext.php","Line":405,"CustomMessage":"Error during service alias registration of files_trashbin: Call to a member function getContainer() on null"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36","version":"21.0.0.18"}
{"reqId":"nrNFo5EuLxNqUUqtDkWb","level":3,"time":"2021-03-29T03:48:04+00:00","remoteAddr":"192.168.10.92","user":"Hakim","app":"PHP","method":"POST","url":"/index.php/settings/apps/enable","message":{"Exception":"Error","Message":"Undefined index: settings at /var/www/nextcloud/lib/private/AppFramework/Bootstrap/RegistrationContext.php#404","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/RegistrationContext.php","line":404,"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":143,"function":"delegateContainerRegistrations","class":"OC\\AppFramework\\Bootstrap\\RegistrationContext","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":86,"function":"registerApps","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/lib/private/Installer.php","line":146,"function":"runLazyRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/apps/settings/lib/Controller/AppSettingsController.php","line":448,"function":"installApp","class":"OC\\Installer","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":218,"function":"enableApps","class":"OCA\\Settings\\Controller\\AppSettingsController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":127,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":993,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36","version":"21.0.0.18"}
{"reqId":"nrNFo5EuLxNqUUqtDkWb","level":3,"time":"2021-03-29T03:48:04+00:00","remoteAddr":"192.168.10.92","user":"Hakim","app":"no app in context","method":"POST","url":"/index.php/settings/apps/enable","message":{"Exception":"Error","Message":"Call to a member function getContainer() on null","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":143,"function":"delegateContainerRegistrations","class":"OC\\AppFramework\\Bootstrap\\RegistrationContext","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":86,"function":"registerApps","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/lib/private/Installer.php","line":146,"function":"runLazyRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/apps/settings/lib/Controller/AppSettingsController.php","line":448,"function":"installApp","class":"OC\\Installer","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":218,"function":"enableApps","class":"OCA\\Settings\\Controller\\AppSettingsController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":127,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":993,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/RegistrationContext.php","Line":405,"CustomMessage":"Error during service alias registration of settings: Call to a member function getContainer() on null"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36","version":"21.0.0.18"}
{"reqId":"nrNFo5EuLxNqUUqtDkWb","level":3,"time":"2021-03-29T03:48:04+00:00","remoteAddr":"192.168.10.92","user":"Hakim","app":"PHP","method":"POST","url":"/index.php/settings/apps/enable","message":{"Exception":"Error","Message":"Undefined index: workflowengine at /var/www/nextcloud/lib/private/AppFramework/Bootstrap/RegistrationContext.php#404","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/RegistrationContext.php","line":404,"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":143,"function":"delegateContainerRegistrations","class":"OC\\AppFramework\\Bootstrap\\RegistrationContext","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":86,"function":"registerApps","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/lib/private/Installer.php","line":146,"function":"runLazyRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/apps/settings/lib/Controller/AppSettingsController.php","line":448,"function":"installApp","class":"OC\\Installer","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":218,"function":"enableApps","class":"OCA\\Settings\\Controller\\AppSettingsController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":127,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":993,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36","version":"21.0.0.18"}
{"reqId":"nrNFo5EuLxNqUUqtDkWb","level":3,"time":"2021-03-29T03:48:04+00:00","remoteAddr":"192.168.10.92","user":"Hakim","app":"no app in context","method":"POST","url":"/index.php/settings/apps/enable","message":{"Exception":"Error","Message":"Call to a member function getContainer() on null","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":143,"function":"delegateContainerRegistrations","class":"OC\\AppFramework\\Bootstrap\\RegistrationContext","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":86,"function":"registerApps","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/lib/private/Installer.php","line":146,"function":"runLazyRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/nextcloud/apps/settings/lib/Controller/AppSettingsController.php","line":448,"function":"installApp","class":"OC\\Installer","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":218,"function":"enableApps","class":"OCA\\Settings\\Controller\\AppSettingsController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":127,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":993,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/lib/private/AppFramework/Bootstrap/RegistrationContext.php","Line":405,"CustomMessage":"Error during service alias registration of workflowengine: Call to a member function getContainer() on null"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36","version":"21.0.0.18"}
{"reqId":"iPqRMxgChg66VQniutC1","level":3,"time":"2021-03-29T03:48:06+00:00","remoteAddr":"192.168.10.92","user":"Hakim","app":"no app in context","method":"GET","url":"/index.php/apps/files","message":{"Exception":"Error","Message":"Interface 'OCA\\Files_External\\Lib\\Config\\IBackendProvider' not found","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/composer/composer/ClassLoader.php","line":476,"function":"include"},{"file":"/var/www/nextcloud/lib/composer/composer/ClassLoader.php","line":344,"function":"Composer\\Autoload\\includeFile"},{"function":"loadClass","class":"Composer\\Autoload\\ClassLoader","type":"->"},{"file":"/var/www/nextcloud/apps/sharepoint/lib/AppInfo/Application.php","line":38,"function":"spl_autoload_call"},{"file":"/var/www/nextcloud/apps/sharepoint/appinfo/app.php","line":6,"function":"registerBackendProvider","class":"OCA\\SharePoint\\AppInfo\\Application","type":"->"},{"file":"/var/www/nextcloud/lib/private/legacy/OC_App.php","line":295,"args":["/var/www/nextcloud/apps/sharepoint/appinfo/app.php"],"function":"require_once"},{"file":"/var/www/nextcloud/lib/private/legacy/OC_App.php","line":177,"function":"requireAppFile","class":"OC_App","type":"::"},{"file":"/var/www/nextcloud/lib/private/legacy/OC_App.php","line":137,"function":"loadApp","class":"OC_App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":979,"function":"loadApps","class":"OC_App","type":"::"},{"file":"/var/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/apps/sharepoint/lib/Backend/Provider.php","Line":31,"CustomMessage":"App sharepoint threw an error during app.php load and will be disabled: Interface 'OCA\\Files_External\\Lib\\Config\\IBackendProvider' not found"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36","version":"21.0.0.18"}

Thanks,
Hakim