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

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:

Any thoughts?

The output of your Nextcloud log in Admin > Logging:

$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' => '',
  'overwriteprotocol' => 'https',
  'trusted_proxies' =>
  array (
    0 => '',
    1 => '',
    2 => '',
  'passwordsalt' => 'lol',
  'secret' => 'lol',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => '',
    2 => '',
    3 => '',
    4 => '',
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'pgsql',
  'version' => '',

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

I’m seeing this a lot, not any errors I can tell - - [16/Aug/2023:14:37:15 +0000] "GET /status.php HTTP/2.0" 200 170 "-" "kube-probe/1.25"```

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:

$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' => '',
  '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,

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.


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, 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