Persistent Redirection Issue with Nextcloud on TrueNAS Using Cloudflare Tunnel

Hello everyone,

I’m trying to setup a Nextcloud instance for the owners corporation of my appartment building on our own server that i’ve setup (we had a data loss so now everyone is taking IT seriously for once, hence they let me setup TrueNAS with backblaze backups and RAIDZ2).

I’m encountering a persistent issue where my Nextcloud instance, hosted on a TrueNAS server and accessed via Cloudflare Tunnel, is redirecting from https://cloud.mydomain.com to https://cloud.mydomain.com:9001/login, resulting in a timeout. Strangely, when I manually remove the port number from the URL, I can access the login page and use Nextcloud normally (i.e. change the url to: https://cloud.mydomain.com/login). After logging in it tries to redirect to https://cloud.mydomain.com:9001/apps/dashboard. Again after removing the :9001 it largely works as intended. However some links, but not all, within the Nextcloud UI also include the unwanted port number.

I am not using a reverse proxy (other than the Cloudflare tunnel).
The Tunnel is setup as such:

Public hostname
Subdomain   .   Domain (Required)   /  Path
cloud       .   mydomain.com        / 

Service
Type(Required) :// URL(Required)
HTTPS          :// (Internal IPV4 of TrueNAS Server):9001

I’ve tried looking through forum posts and using chat GPT to come up with a solution. I’ve tried a number of troubleshooting steps to resolve this issue, but so far, I’ve had no luck. Here’s a summary of what I’ve done:

  1. Checked and corrected the config.php file of Nextcloud, ensuring settings like overwritehost and overwrite.cli.url are set to ‘cloud.mydomain.com’ without a port number.
  2. Cleared browser cache and tested with incognito mode to rule out client-side caching issues.
  3. Confirmed there are no Cloudflare Page Rules or Workers that could be causing redirects to include the port number. Also purged Cloudflare cache.
  4. Reviewed .htaccess and web server (reverse proxy) configurations for any redirection rules. No reverse proxy is currently known to be configured unless it’s part of Cloudflare Tunnel by default.
  5. Restarted the TrueNAS server completely, hoping to refresh all services and configurations.
  6. Checked for any hard-coded port numbers in Nextcloud’s database (pgsql), but found none.
  7. Ensured that the Cloudflare Tunnel is not configured to append a port number to requests.

Despite these steps, the issue persists. The Nextcloud setup is running in a Docker container on TrueNAS, and I’ve ensured that the environment is as clean as possible before testing again.

I’m reaching out for help or suggestions on what might be causing this redirect issue and how to resolve it. If anyone has experienced something similar or has insights into the problem, I’d greatly appreciate your input.

Thank you in advance for your time and assistance!

Oh, I should also probably say that I am using the Tunnel to access the TrueNAS interface and another docker image behind the Cloudflare TOTP email access. So I know that things are redirecting properly. I don’t know if that changes anything …