Nexcloud redirecting to ip

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): 2.4.38
PHP version (eg, 7.4): 7.3.31

The issue you are facing: When going to the domain I get redirected to the servers local ip even when outside of my network

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

Steps to replicate it:

  1. Setup nginx reverse proxy on a seperate server
  2. Have it proxy to nextcloud
  3. Set overwrite host in nextcloud

Nextcloud config

<?php
$CONFIG = array (
  'overwritehost' => 'cloud.example.com',
  'passwordsalt' => 'no',
  'secret' => 'its a secret',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '192.168.5.158',
    2 => 'cloud.example.com'
  ),
  'datadirectory' => '/mnt/sandisk',
  'dbtype' => 'mysql',
  'version' => '22.2.5.1',
  'overwrite.cli.url' => 'https://cloud.example.com',
  'dbname' => 'nope',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'still no',
  'dbpassword' => 'how about no',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'instanceid' => 'probably should be removed',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'updater.secret' => 'stuff',
);

Nginx reverse proxy config file Other server:

server {
    listen 80;
    server_name cloud.example.com;
    return 301 https://$server_name$request_uri;
}

server { 
  listen 443 ssl http2; 
  server_name cloud.example.com; 
 
 ssl_certificate /etc/letsencrypt/live/cloud.example.com/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/cloud.example.com/privkey.pem;

  location / { 
      proxy_pass http://192.168.5.158:80;
      proxy_set_header X-Forwarded-For $remote_addr;
      client_max_body_size 50G; 
  } 
}

could be 'overwrite.cli.url' => 'https://xxxxxxxxxxxxxxx', missing in …/nextcloud/config/config.php

It exists line 15

my mistake, sorry…

do you have a .htaccess file ?

Yeah I have one

and … ?

No rewritte/redirect in it ?

Also, could you provide excerp of :

…/etc/apache2/apache2.conf
…/etc/apache2/sites-enabled/*.conf
…/etc/apache2/mods-enabled

Here are the rewrites for .htaccess I will send apache files soon

  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT} DavClnt
  RewriteRule ^$ /remote.php/webdav/ [L,R=302]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
  RewriteRule ^remote/(.*) remote.php [QSA,L]
  RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
  RewriteRule ^\.well-known/(?!acme-challenge|pki-validation) /index.php [QSA,L]
  RewriteRule ^(?:\.(?!well-known)|autotest|occ|issue|indie|db_|console).* - [R=404,L]
</IfModule>```

If needed, i have some working examples :

I have them as the default besides config.php so I am assuming they would work