Nginx reverse proxy multiple domains

Nextcloud version (eg, 20.0.5): 22.2.5
Operating system and version (eg, Ubuntu 20.04): Debian 10
Apache or nginx version (eg, Apache 2.4.25): nginx (reverse proxy), apache (local)

The issue you are facing:

I try to configure my nextcloud instance to make it accessible by multiple domains. (With just one domain everything works like expected)

For that I added a new site to my nginx reverse proxy (to provide a ssl certificate for the new domain). The nginx reverse proxy ip address and internal domain name are entries of “trusted_domains” in config.php

As soon as I access my nextcloud via the new domain (domain 2) it gets rewritten to the other one (the first one I’ve configured - domain 1). The reason for that is the “overwritehost” option in my config.php file which is needed that I can access my nextcloud via a reverse proxy with domain 1.

Is there a possibility to make my nextcloud accessible without the need of overwriting the host?
Or can it be configured in that way that the url gets overwritten with domain 1 if I access it via this domain and to domain 2 if I use the new one (e.g. like the client ip address via x-forwarded-for header)?

As soon as I remove the overwritehost and add domain 1 and domain 2 to the “trusted_domains” I get the error:
“Access through untrusted domain”

I get the same error as well if I remove the second domain and just use the first one. So this setting is needed to be able to access my nextcloud instance via my reverse proxy.

Thank you for your help

Hi all,

I’m trying to accomplish the exact same thing but with Caddy. Two domains with one NC instance behind the reverse proxy. Is there any possibility to get this to work?

Interestingly enough, I use HomeAssistant with the same proxy configuration and HomeAssistant automatically recognizes the correct (accessed) domain.

@gimly: Have you found a solution or workaround?

Thanks very much

I also would like to have an answer to this.

  'trusted_domains' => 
  array (
    0 => 'cloud.domain1.com',
    1 => 'cloud.domain2.com',

No problem on trusted_domains, it is an array with multiple atries.

BUT:

  'overwrite.cli.url' => 'https://cloud.domain1.com',
  'overwritehost' => 'cloud.domain1.com',

... does NOT allow that, these values are NOT an array.

So, how to access NC via 2 diffent domains??

Thanks ind advance! :wave: