Domain redirects to local IP using cloudflare on TrueNAS

Versions

  • Nextcloud version: 31.0.0 (latests feb 25th release)
  • TrueNAS Scale version: 24.04 (dragonfish):
  • Web server I don’t know since I’m running the docker from TrueNAS Scale
  • I think inside the docker, there’s a nginx container as well, but:
  • Using cloudflared to access remotely: version is latests available on truenas scale
  • Is this the first time you’ve seen this error? (Yes / No): Yes, it has happened ever since i bought a domain and I’m only making an issue now.
  • When did this problem seem to first start? Ever since buying and using a domain
  • Are you using CloudfIare, mod_security, or similar? (Yes / No) - I’m using CloudflareD, so yeah i think

The Issue

In certain parts of the service, Nextcloud will give the local IP instead of the domain, No matter from where you access it.

Examples:

  1. Trying to login, or the initial redirect → redirects properly but to the local IP instead of continuing the domain
  2. Sharing a file returns the URL with an IP instead of domain name - And even when you modify it when you send it, for videos, i can see it is making a query to the local ip (so it’ll look like the content is unavailable, but I can see it’s looking for the ip, caused me so much trouble)
  3. The WebDAV example URL to copy+paste don’t use the domain

Steps to replicate it

  1. Configure nextcloud container in TrueNAS Scale to use the local IP, initially intended to use Tailscale
  2. Setup cloudflared on TrueNAS Scale, which should → redirect nextcloud.example.com to 192.168.0.1:9001
  3. CloudflareD does the job, it shows the website
  4. Find the current issue - domain returns the IP
  5. Try configuring /config/config.php and setting every overwrite host values domains to use nextcloud.example.com (mentioned below)
  6. Nextcloud behaves the same

Said thing managed to fix the fact that the domain wasn’t even allow, but setting it as a trusted domain worked.

Configuration

Nextcloud

# occ config:list
{
    "system": {
        "htaccess.RewriteBase": "\/",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "password": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        },
        "upgrade.disable-web": true,
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "nextcloud.MYDOMAIN.COM",
            "nextcloud",
            "MY.LOCAL.IP.ADDRESS",
            "localhost",
            "127.0.0.1",
            "nextcloud-init-sync.lock"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "pgsql",
        "version": "31.0.0.18",
        "overwrite.cli.url": "https:\/\/[nextcloud.MYDOMAIN.COM]",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "overwritehost": "[MY.LOCAL.IP.ADDRESS]",
        "overwriteprotocol": "https",
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "app_install_overwrite": [
            "pandoc"
        ],
        "loglevel": 0,
        "maintenance": false
    },
    "apps": {
        "activity": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "app_api": {
            "types": "",
            "enabled": "yes",
            "installed_version": "5.0.2"
        },
        "backgroundjob": {
            "lastjob": "103"
        },
        "bruteforcesettings": {
            "types": "",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "calendar": {
            "types": "",
            "enabled": "yes",
            "installed_version": "5.2.1"
        },
        "cfg_share_links": {
            "types": "",
            "enabled": "yes",
            "installed_version": "7.0.1"
        },
        "circles": {
            "types": "filesystem,dav",
            "enabled": "yes",
            "installed_version": "31.0.0-dev.0",
            "loopback_tmp_scheme": "https",
            "migration_22": "1",
            "maintenance_update": "{\"3\":1744399804,\"2\":1744401604,\"1\":1744401604}",
            "maintenance_run": "0",
            "migration_run": "0"
        },
        "cloud_federation_api": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "1.14.0"
        },
        "comments": {
            "types": "logging",
            "enabled": "yes",
            "installed_version": "1.21.0"
        },
        "contactsinteraction": {
            "types": "dav",
            "enabled": "yes",
            "installed_version": "1.12.0"
        },
        "core": {
            "installedat": "1733093835.5345",
            "vendor": "nextcloud",
            "public_files": "files_sharing\/public.php",
            "lastupdatedat": 1744395363,
            "backgroundjobs_mode": "cron",
            "lastcron": 1744401645,
            "moveavatarsdone": "yes",
            "previewsCleanedUp": "1",
            "metadataGenerationDone": true,
            "lastupdateResult": "{\"version\":\"31.0.3.2\",\"versionstring\":\"Nextcloud 31.0.3\",\"url\":\"https:\\\/\\\/download.nextcloud.com\\\/server\\\/releases\\\/nextcloud-31.0.3.zip\",\"web\":\"https:\\\/\\\/docs.nextcloud.com\\\/server\\\/31\\\/admin_manual\\\/maintenance\\\/upgrade.html\",\"changes\":\"https:\\\/\\\/updates.nextcloud.com\\\/changelog_server\\\/?version=31.0.3\",\"autoupdater\":\"1\",\"eol\":\"0\"}",
            "files_metadata": {
                "photos-original_date_time": {
                    "value": null,
                    "type": "int",
                    "etag": "",
                    "indexed": true,
                    "editPermission": 0
                },
                "photos-exif": {
                    "value": null,
                    "type": "array",
                    "etag": "",
                    "indexed": false,
                    "editPermission": 0
                },
                "photos-ifd0": {
                    "value": null,
                    "type": "array",
                    "etag": "",
                    "indexed": false,
                    "editPermission": 0
                },
                "photos-size": {
                    "value": null,
                    "type": "array",
                    "etag": "",
                    "indexed": false,
                    "editPermission": 0
                },
                "blurhash": {
                    "value": null,
                    "type": "string",
                    "etag": "3d507662260bb63db4e58830b49b7cf7",
                    "indexed": false,
                    "editPermission": 0
                },
                "files-live-photo": {
                    "value": null,
                    "type": "string",
                    "etag": "",
                    "indexed": false,
                    "editPermission": 1
                }
            },
            "oc.integritycheck.checker": []
        },
        "dashboard": {
            "types": "",
            "enabled": "yes",
            "installed_version": "7.11.0"
        },
        "dav": {
            "types": "filesystem",
            "enabled": "yes",
            "regeneratedBirthdayCalendarsForYearFix": "yes",
            "buildCalendarSearchIndex": "yes",
            "builtSocialSearchIndex": "yes",
            "buildCalendarReminderIndex": "yes",
            "installed_version": "1.33.0",
            "chunks_migrated": "1"
        },
        "deck": {
            "enabled": "yes",
            "types": "dav",
            "installed_version": "1.15.0"
        },
        "drawio": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "3.0.9"
        },
        "federatedfilesharing": {
            "types": "",
            "enabled": "yes",
            "installed_version": "1.21.0"
        },
        "federation": {
            "types": "authentication",
            "enabled": "yes",
            "installed_version": "1.21.0"
        },
        "files": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "2.3.1"
        },
        "files_downloadlimit": {
            "types": "",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "files_pdfviewer": {
            "types": "",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "files_reminders": {
            "types": "",
            "enabled": "yes",
            "installed_version": "1.4.0"
        },
        "files_sharing": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "1.23.1"
        },
        "files_trashbin": {
            "types": "filesystem,dav",
            "enabled": "yes",
            "installed_version": "1.21.0"
        },
        "files_versions": {
            "types": "filesystem,dav",
            "enabled": "yes",
            "installed_version": "1.24.0"
        },
        "firstrunwizard": {
            "enabled": "yes",
            "types": "",
            "installed_version": "4.0.0"
        },
        "intros": {
            "types": "",
            "installed_version": "1.1.2",
            "enabled": "yes"
        },
        "libresign": {
            "enabled": "no",
            "types": "",
            "installed_version": "10.6.4"
        },
        "logreader": {
            "types": "logging",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "lookup_server_connector": {
            "types": "authentication",
            "enabled": "yes",
            "installed_version": "1.19.0"
        },
        "nextcloud_announcements": {
            "types": "logging",
            "enabled": "yes",
            "installed_version": "3.0.0",
            "pub_date": "Thu, 24 Oct 2019 00:00:00 +0200"
        },
        "notes": {
            "installed_version": "4.11.0",
            "types": "",
            "enabled": "yes"
        },
        "notifications": {
            "types": "logging",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "oauth2": {
            "types": "authentication",
            "enabled": "yes",
            "installed_version": "1.19.1"
        },
        "pandoc": {
            "installed_version": "0.7.0",
            "types": "",
            "enabled": "yes"
        },
        "password_policy": {
            "types": "authentication",
            "enabled": "yes",
            "installed_version": "3.0.0"
        },
        "photos": {
            "types": "dav,authentication",
            "enabled": "yes",
            "installed_version": "4.0.0-dev.1",
            "lastPlaceMappedUser": "admin",
            "lastPlaceMappingDone": "true"
        },
        "privacy": {
            "types": "",
            "enabled": "yes",
            "installed_version": "3.0.0"
        },
        "profile": {
            "installed_version": "1.0.0",
            "types": "",
            "enabled": "yes"
        },
        "provisioning_api": {
            "types": "prevent_group_restriction",
            "enabled": "yes",
            "installed_version": "1.21.0"
        },
        "recommendations": {
            "types": "",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "related_resources": {
            "types": "",
            "enabled": "yes",
            "installed_version": "2.0.0"
        },
        "richdocuments": {
            "types": "prevent_group_restriction",
            "wopi_url": "https:\/\/[MY.LOCAL.IP.ADDRESS:PORT]\/custom_apps\/richdocumentscode\/proxy.php?req=",
            "disable_certificate_verification": "",
            "enabled": "no",
            "installed_version": "8.5.5"
        },
        "richdocumentscode": {
            "enabled": "no",
            "types": "",
            "installed_version": "24.4.1302"
        },
        "serverinfo": {
            "types": "",
            "enabled": "yes",
            "installed_version": "3.0.0",
            "cached_count_storages": "3",
            "cached_count_filecache": 4549,
            "size_appdata_storage": -1,
            "cached_count_appdata_files": 2864
        },
        "settings": {
            "types": "",
            "installed_version": "1.14.0",
            "enabled": "yes"
        },
        "sharebymail": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "1.21.0"
        },
        "support": {
            "types": "session",
            "enabled": "yes",
            "installed_version": "3.0.0",
            "SwitchUpdaterServerHasRun": "yes"
        },
        "survey_client": {
            "types": "",
            "enabled": "yes",
            "installed_version": "3.0.0"
        },
        "systemtags": {
            "types": "logging",
            "enabled": "yes",
            "installed_version": "1.21.1"
        },
        "tasks": {
            "installed_version": "0.16.1",
            "types": "",
            "enabled": "yes"
        },
        "text": {
            "types": "dav",
            "enabled": "yes",
            "installed_version": "5.0.0"
        },
        "theming": {
            "types": "logging",
            "enabled": "yes",
            "installed_version": "2.6.1"
        },
        "twofactor_backupcodes": {
            "types": "",
            "enabled": "yes",
            "installed_version": "1.20.0"
        },
        "updatenotification": {
            "types": "",
            "enabled": "yes",
            "installed_version": "1.21.0",
            "intros": "1.1.2",
            "drawio": "3.0.9",
            "whiteboard": "1.0.5",
            "cfg_share_links": "7.0.1",
            "core": "31.0.3.2",
            "calendar": "5.2.1",
            "richdocumentscode": "24.4.1002",
            "deck": "1.14.4",
            "update_check_errors": 0
        },
        "user_status": {
            "types": "",
            "enabled": "yes",
            "installed_version": "1.11.0"
        },
        "viewer": {
            "types": "",
            "enabled": "yes",
            "installed_version": "4.0.0"
        },
        "weather_status": {
            "types": "",
            "enabled": "yes",
            "installed_version": "1.11.0"
        },
        "webhook_listeners": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "1.2.0"
        },
        "whiteboard": {
            "enabled": "yes",
            "installed_version": "1.0.5",
            "types": ""
        },
        "workflowengine": {
            "types": "filesystem",
            "enabled": "yes",
            "installed_version": "2.13.0"
        }
    }
}
# cat config/config.php 
<?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,
    ),
  ),
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'nextcloud-redis',
    'password' => '[REDACTED]',
    'port' => 6379,
  ),
  'upgrade.disable-web' => true,
  'passwordsalt' => '[REDACTED]',
  'secret' => '[REDACTED]',
  'trusted_domains' => 
  array (
    0 => 'nextcloud.MYDOMAIN.COM',
    1 => 'nextcloud',
    2 => 'MY.LOCAL.IP.ADDRESS',
    3 => 'localhost',
    4 => '127.0.0.1',
    5 => 'nextcloud-init-sync.lock',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'pgsql',
  'version' => '31.0.0.18',
  'overwrite.cli.url' => 'https://nextcloud.MYDOMAIN.COM',
  'dbname' => 'nextcloud',
  'dbhost' => 'nextcloud-postgres:5432',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'oc_admin',
  'dbpassword' => '[REDACTED]',
  'installed' => true,
  'instanceid' => '[REDACTED]',
  'overwritehost' => 'nextcloud.MYDOMAIN.COM',
  'overwriteprotocol' => 'https',
  'trusted_proxies' => 
  array (
    0 => '172.17.0.0/16',
    1 => '172.16.0.0/16',
    2 => '127.0.0.1',
    3 => 'MY.LOCAL.IP.ADDRESS',
  ),
  'app_install_overwrite' => 
  array (
    0 => 'pandoc',
  ),
  'loglevel' => 0,
  'maintenance' => false,
);

What I tried

I tried configuring /config/config.php in the nextcloud container, and that didn’t seem to work. overwrite.cli.url didn’t do the trick, and neither did overwritehost.

Note that using the domain by itself works sometimes, in certain areas. And so does the IP. It’s not that it always happens.

Related

Didn’t work for me, it’s not an always problem, just sometimes:

Issue on Github:

PR where it is supposed to be fixed: (might not be the same one if so)

Notes, extra info

There’s a host option in TrueNAS Scale. Said option changes where it should be hosted at. I can’t set the domain here since I’m using cloudflare to manage that, the DNS resolving n stuff. And I need to have a resolvable domain, so an IP, that I can feed to cloudflareD. This is likely a big factor, but I don’t know how work around it.
If you feel like this is totally related to TrueNAS, I’ll try making an issue on their forums.

must be your public domain.

That’s… so weird.

# occ config:list | grep -i overwritehost
        "overwritehost": "[MY.LOCAL.IP.ADDRESS]"
# cat config/config.php | grep -i overwritehost
  'overwritehost' => 'nextcloud.[MYDOMAIN.COM]',

How come?? The container has been restarted multiple times since I had changed that.

I’ll investigate this.

I’ve found some things out:

  1. No matter what I do, it keeps setting it as the local IP
  2. I found out that TrueNAS Scale sets an environment variable (/etc/environment), particularly the host value on the container configuration. Which sets the env OVERWRITEHOST

I found the solution:

In general:

  1. Keep overwritehost as your domain name (in config.php)
  2. Add overwriteprotocol set to ‘https’ (in config.php)
  3. Use overwritecondaddr to apply these settings only for external traffic
'overwritehost' => 'nextcloud.[MYDOMAIN.COM]',
'overwriteprotocol' => 'https',
'overwritecondaddr' => '^(?!192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])).*$',  // Apply to non-RFC1918 addresses (i.e., external) - this will work on any local address range.

Which still means you have to change trusted stuff, this assume that step was done.

Or the way I did it, specific for TrueNAS Scale:

  1. instead of overwritehost, change the host variable in the container configuration panel. It will take precedence over anything you set using occ or config.php
  2. overwriteprotocol I don’t know how I did it, sorry. But I always enforce https whereever I can.
  3. overwritecondaddr is a variable that can be set under Additional Environment Variables. Add one and name it OVERWRITECONDADDR (watch out for the D next to CON), and add the aforementioned value.
  4. Restart

Check with occ config:list, since that will always have the value that it’s actually using.
Check the environment variables with echo &VARIABLE

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.