Nextcloud keeps redirecting to localhost

Nextcloud version (eg, 27.0.5): 27.0.1
Operating system and version (eg, Ubuntu 20.04): truenas scale
Apache or nginx version (eg, Apache 2.4.25): nginx
PHP version (eg, 7.4): ?

The issue you are facing:

I have nextcloud up and running in a truenas scale (the linux version) as an app. Whenever I go to nextcloud i want to go to the URL https://cloud.xxx.com:zzzz.

Whenver I log in, I am immediate redirect to the localhost, https://192.168.x.x:zzzz

Now as long as I am on the localhost this works, but obviously if I am outside my network it’s causing problems and updating is a problem, etc.

Your first thought would be just update the config.php file, well I’ve done that. For example, when I click on the logo in the top right hand corner the logo links to: https://192.168.1.104:zzzz/

Any thoughts?

The output of your Nextcloud log in Admin > Logging:

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'overwritehost' => 'https://cloud.xxxx.com:zzzz',
  'overwriteprotocol' => 'https',
  'trusted_proxies' =>
  array (
    0 => '127.0.0.1',
    1 => 'xxx.xxx.xxx.xxx:zzzz',
    2 => 'cloud.xxxx.com:9495',
  ),
  'passwordsalt' => 'lol',
  'secret' => 'lol',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => '192.168.1.104',
    2 => 'cloud.xxxx.com',
    3 => 'www.cloud.xxxx.com',
    4 => 'cloud.xxxx.com:zzzz',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'pgsql',
  'version' => '27.0.2.1',

The output of your Apache/nginx/system log in /var/log/____:

I’m seeing this a lot, not any errors I can tell

172.16.0.1 - - [16/Aug/2023:14:37:15 +0000] "GET /status.php HTTP/2.0" 200 170 "-" "kube-probe/1.25"```

Hello!
In fact, we don’t use the overwritehost in our config file at all; but that can also be because we don’t use truenas. But what is different is that we have written our domains in the array; only your IP address is in here. So it’s best to write in your domain as well and then try again!
With us, the beginning of the config file looks something like this:

<?php
$CONFIG = array (
  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'K/XXX',
  'trusted_domains' =>
  array (
    0 => 'IP-ADRESSE',
    1 => 'DOMAIN_NAME_1',
    2 => 'DOMAIN_NAME_2',
  ),
  'datadirectory' => '/mnt/SSD1/nextcloud',
  'dbtype' => 'mysql',
  'version' => '27.0.2.1',
  'overwrite.cli.url' => 'DOMAIN_NAME',
  'htaccess.RewriteBase' => '/',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'USERNAME_DBUSER',
  'dbpassword' => 'PASSWORD_DBPASSWORD',
  'installed' => true,
  'app_install_overwrite' =>
  array (
    0 => 'printer',
    1 => 'files_trackdownloads',
    2 => 'admin_notifications',
...

I hope I could help you!
If you have any further questions, please feel free to get back to us!
Best regards,
schBenedikt

Hi there,

Okay I posted my full edited config.php so you can see the rest of the settings sorry. I’ve also edited the problem, these are my current settings and I still cannot connect securely outside my local network, my URLs keep being changed to my localhost.

Thanks!

at first glance your config looks good. Maybe overwrite.cli.url would be last polish but first steps should work now already. did you try removing cache or using incognito window?

Maybe this threads help you:

as you are setting TRUSTED_PROXIES I assume you are running behing reverse proxy - maybe it’s worth review it’s config.

btw: there is no need to add cloud URL to TRUSTED_PROXIES

I’m going to bump this as I am having the same issue. This wasn’t an issue for me before the NextCloud app on Truenas Scale update v. 27.0.0
That was the first time the app required an internal certification for the upgrade. I had been using mine from behind a reverse proxy performing SSL offloading since the Scale app was released. Now I am also having this exact problem.

Any updates?

what kind of updates do you expect? I liked two posts where you can see more details. If your issue is different please describe what you tried and which issues do you see.

I may have fixed this problem. I was not crazy, it WAS re-writing my nextcloud admin settings all the time. This actually was my clue.

If you are running nextcloud as an app in truenas scale BE SURE TO UPDATE THE APP URL IN TRUENAS! In the nextcloud app settings my nextcloud host was set to my IP address, which was fine when I was initially trying to get it set up and installed. After changing this setting in the truenas app settings to cloud.xxxx.com, and then having my port specified in those settings as well, things appear to be working.

The truenas nextcloud app will force those app settings over anything you set in the config.php file, hence why any of my config.php updates were not working. Hopefully this fixes the problem for good.

1 Like

EXCEPT if you click on the “WebPortal” button inside TrueNas Apps Page…
Because it will redirect to https://cloud.xxx.com:9001
So if you don’t want that stupid port just redirect the external Acces Port to 443 and manually enter cloud.xxx.com and it works!

1 Like