HowTo: Add a new trusted domain

Trusted domains are used by Nextcloud to prevent Host Header Poisoning. You need to specify every domain at which your Nextcloud can be accessed.

This means if you have Nextcloud installed at “192.168.0.29” and also want it to be accessible at “cloud.example.com” you’d need to modify the trusted_domains entry in your config/config.php. The initial config would look like the following:

  'trusted_domains' =>
  array (
    0 => '192.168.0.29',
  ),

To add a new domain just add new entries by appending a new item to the PHP array:

  'trusted_domains' =>
  array (
    0 => '192.168.0.29',
    1 => 'cloud.example.com',
  ),

If you use an environment where your IP address can change multiple times it is recommended to configure your DNS server in a way to resolve to the IP instead of accessing the IP address manually.

Note: Nextcloud is optimised for usage with just a single domain. It is thus recommended to stay with just one domain instead of using multiple ones.

12 Likes
Add all private IPs (local network) to Trusted Devices
Error url trusted_domains
NextCloud Box - Use of static IP address
How-to/FAQ WIKI
Trouble connecting to local Nextcloud box through wifi with android
How to add domain name to nextcloud
No access after config.php change, php error, http error 500, SimpleContainer.php:110 error
Remote and local server setup?
How to get around "access through untrusted domain" error
Nextcloud + Static IP
Problem with Logging into NextCloud on Kuberbetes on Raspberrypi Stack
Adding trusted Domains doesnt work
Https not working on nextcloud
New Install - Unable to login to created user
Nextcloud change domain url from example.com/nextcloud to example.com/
Feedback on plans for migrating from a Digital Ocean instance to a physical server
Managing multiple Nextcloud multiple sites
I can't manage trust domains
New installation with Docker and OMV and Im getting an error "Trusted domains" how do I fix it?.
Access through untrusted domain Please contact your administrator pls help
NextCloud 11 ready Raspbian image with extras
Using reverse proxy for next cloud on Truenas scale error
Can't connect to Netxcloud from Tailscale in GNOME
Paid Support for LDAP Migration - Same NC version but different AD domain naming
Connection Error : You do not have permission to complete the operation
Dual domain with one nextcloud instance
Nextcloud e tailscale
Migrating to new domain
(Depreciated) Looking for help setting up a Reverse Proxy (TrueNAS / FreeBSD / Caddy)
Cannot log in via my LAN address
My first post. problem with remote access - “access through untrusted domain” Please see documentation
"trusted domains"setting
How do I add a valid domain?
IIS as reverse proxy for NC - NC does not 'see itself'
Error 500,503 on fresh installation
URL fĂźr Nextcloudinstallation wechseln
Accessing Nextcloud on my home network
Zugriff Ăźber eine nicht vertrauenswĂźrdige Domain
Public IP showes up in config.php
Nextcloud does not recognize trusted domain
Connection to nextcloud server behinde private ip
Zugriff Ăźber nicht vertrauenswĂźrdige seite auf VM in ESXI
Ubuntu server - Trusted_domains
After activating https i get error "untrusted domain"
Need Help with "untrusted domain" setup
Internal server error after change in ISP
Nextcloud trusted domain switch
Can't Connect to fresh install on SSH

Thought I would simply give a thanks @LukasReschke (& all devs/contributors) . I just created my v10 instance and all is working great.

I take a look at the logs and within 10 hours of set up on a new hosted server, IP and install I had someone attempt this on my server.

With that said, it would be a interesting feature to add these IPs to a block list as outlined here automatically:

& for nginx folks

… OR to a NC community/crowd-sourced database of bad bots/IPs (with fail2ban?).

With peace-of-mind, I’m moving on and grateful for the awesome work. :+1:

1 Like

I just wanted to add that adding a trusted domain can also easily be done from the command line:

# sudo ./occ config:system:set trusted_domains 2 --value=your.domain

7 Likes

oparoz, would this work within the command line of freenas?

Hi Lukas,

I’m newbie in linux
How to modify config.php?
I have to add new domain but config.php can’t open.
How to modify file/folder permissions?

Please advise

Thanks

Hello @sudarjito,

You must open the file as a super user in order to modify it. For example, if you are using Ubuntu the command to do that is:

$sudo gedit /path/to/your/config/config.php

Although the given example works in Ubuntu, the command shall work well in any system that you have a super user access and gedit installed.

Hy, i have the Same problem, Need some help.
I have to do Config the Config.php to add my trusted domain

I dont know where i find the file/path to edit it.

Hi,
it probably depends on the system you are using.
On my debian-install it’s
/var/www/nextcloud/config/config.php

Edit the file using admin-rights.

Cheers,
Oliver

Hi,
I got problem to config “Add Trusted Domain” in Own Cloud using Cent OS.
I hope you guys have the solution. tq

hello - i’m new inhere …

  • i’ve installed ‘nextcloud’ on a centos-7, under /var/www/html/192.168.1.220/ …

  • but now i’ve got a new different fixed ip-address from my ‘isp’ - so how
    do i change to the new ip-addr. without ‘messing’ my current build/setup?


grdt.

@gnugrdt

Why would you do that?

On the other hand, its just a foldername, and therefore a bad design desicion, but who cares. I allways use /var/www/nextcloud.

You can just leave this (changes here are not recommended). What really counts here is your DNS setup and config.php, since DNS virtualises IP adresses away for that manner.

Supplement: What does 192.168.* has to do with your ISP? What the … ?

To not open a new thread about the same, I added 192.168.1.16…

sudo nextcloud.occ config:system:set trusted_domains 1 --value=192.168.1.16
System config value trusted_domains => 1 set to string 192.168.1.16

sudo nextcloud.occ config:system:get trusted_domains
localhost
192.168.1.16

But nextcloud insist to add the IP to trusted domains.

No idea about that?

Hi,
I have the same problem with Giu.
I added a new router and created a bridge connection with my old one which I changed the mode to modem.
After doing that I connected my raspberrypi, where I have the nextcloud installed, to my new router and then I got this screen to add the new ip to the trusted_domains list in config.php.
I did it and still getting the same message.
Any help would be appreciated.

If you’re on a Snap installation, it’ll probably be here:

/var/snap/nextcloud/current/nextcloud/config
3 Likes

I installed Nextcloud 14 from a snap (in Debian 9), so in my case, I had to use the command, as root:

nextcloud.occ config:system:set trusted_domains 2 --value=exampledomain.com

1 Like

I have similar problem… do i need to run other command after “apache2” restart?

1 Like

Problem like this is why I don’t recommended Owncloud/Nextcloud. Keep away and look for other system. Different solutions on different system, and why developer not open it for all domain and let the user blacklist domain on it self is a clue to me. And this is only the start to all the trouble the developer have built in in the system for ordinary people.

On forum how recommended Nextcloud I say no, no, no way. Its a fine idea but for special people. I like Nextcloud but not in the way the developers have put in restrictions that must be forced into the terminal and which solutions are completely different on different systems. The domain response list is just the beginning. Then it’s how big files you can upload and to access dividends through network drives etc.

Yep feel the same way but not only with nextcloud … with the whole damn concept of linux. Great idea but poor execution.

Im currently stuggeling to find the location of said config/ folder. My NC is inside a docker and occ seems to be missing.

It seems that linux devs just assume that the user just happens to know where that file is?

pathtoyoufile/config/config.php

the pathtoyourfile seems to be very very variable as i ftlog can not figure out where its supposed to be.

Why isn’t there an easy way to add these trusted domains inside nextcloud? On many pictures posted here i do see a link that supposedly lets you add the domain directly from the webpage. My nextxloud doesn’t have that feature apparently?

Why so complicated?

purrfect thank you!

1 Like