Caddy & Nextcloud: Redirecting subdomain name to LAN IP address

Nextcloud version (eg, 12.0.2): 13.0.1-apache
Operating system and version (eg, Ubuntu 17.04): Official docker
Apache or nginx version (eg, Apache 2.4.25): Apache
PHP version (eg, 7.1):

The issue you are facing:
When accessing Nextcloud at https://nextcloud.mydomain.com through my proxy (caddy) it will redirect me to my LAN IP address and port 192.168.1.190:6000, even when outside my network (and it does not work outside).

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

Steps to replicate it:

  1. I have a Caddy server with the following Caddyfile:
https://nextcloud.mydomain.com {
    proxy / 192.168.1.190:6000
}
  1. I have a Nextcloud Docker container running on port 6000
  2. Accessing https://nextcloud.quentinmcgaw.info results in a redirection to http://192.168.1.210:6000/apps/files

The output of your Nextcloud log in Admin > Logging:


The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?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,
    ),
  ),
  'instanceid' => 'blablabla',
  'passwordsalt' => 'blablabla',
  'secret' => 'blablabla',
  'trusted_domains' => 
  array (
    0 => '192.168.1.190:6000',
    1 => 'nextcloud.mydomain.info',
  ),
  'datadirectory' => '/var/www/html/data',
  'overwrite.cli.url' => 'https://nextcloud.mydomain.info',
  'dbtype' => 'mysql',
  'version' => '13.0.1.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'nextcloud_database',
  'dbport' => '',
  'dbtableprefix' => '',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'blablabla',
  'installed' => true,
);

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

Solved it, my Caddyfile was missing transparent

https://nextcloud.mydomain.com {
    proxy / 192.168.1.190:6000 {
        transparent
    }
}