Nextcloud Docker with Caddy v2 as reverse proxy

Nextcloud version (eg, 18.0.2):
18.0.4.2

Operating system and version (eg, Ubuntu 20.04):
Debian Buster

Apache or nginx version (eg, Apache 2.4.25):
N/A

PHP version (eg, 7.1):
7.1

The issue you are facing:
White screen when navigating to Nextcloud domain while using Caddy v2 as reverse proxy

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

Steps to replicate it:

  1. Add Nextcloud config to Caddyfile
  2. Navigate to Nextcloud domain

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

<?php
$CONFIG = array (
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'datadirectory' => '/data',
  'trusted_proxies' => 
  array (
    0 => 'letsencrypt',
  ),
  'overwrite.cli.url' => 'https://cloud.haddock.cc/',
  'overwritehost' => 'cloud.haddock.cc',
  'overwriteprotocol' => 'https',
  'trusted_domains' => 
  array (
    0 => 'cloud.haddock.cc',
  ),
  'instanceid' => '[REDACTED]',
  'passwordsalt' => '[REDACTED]',
  'secret' => '[REDACTED]',
  'dbtype' => 'mysql',
  'version' => '18.0.4.2',
  'dbname' => 'nextcloud',
  'dbhost' => 'nextcloud-db:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => 'nextcloud',
  'mysql.utf8mb4' => true,
  'installed' => true,
  'mail_from_address' => 'mail',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'pipe',
  'mail_domain' => 'haddock.cc',
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
    0 => 'admin',
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'mail_smtpport' => '465',
  'mail_smtphost' => 'smtp.sendgrid.net',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'apikey',
  'mail_smtppassword' => '[REDACTED]',
  'mail_smtpsecure' => 'ssl',
);

docker-compose.yml:

nextcloud:
    image: linuxserver/nextcloud
    container_name: nextcloud
    hostname: nextcloud
    environment:
      - PUID=1001
      - PGID=1001
      - TZ=$TZ
    volumes:
      - /opt/docker/config/nextcloud:/config
      - /opt/docker/data/nextcloud:/data
    ports:
      - 8080:80
    depends_on:
      - nextcloud-db
    restart: unless-stopped
  nextcloud-db:
    image: linuxserver/mariadb
    container_name: nextcloud-db
    environment:
      - PUID=1001
      - PGID=1001
      - MYSQL_ROOT_PASSWORD=[REDACTED]
      - MYSQL_PASSWORD=[REDACTED]
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - TZ=$TZ
    volumes:
      - /opt/docker/config/mariadb:/config
    restart: unless-stopped

Caddyfile:

cloud.{$DOMAIN} {
    reverse_proxy nextcloud:443 {
        transport http {
             tls_insecure_skip_verify
        }
    }
}

Caddy output

{"level":"error","ts":1589820896.1618576,"logger":"http.log.error","msg":"tls: first record does not look like a TLS handshake","request":{"method":"GET","uri":"/status.php","proto":"HTTP/1.1","remote_addr":"192.168.50.1:34210","host":"cloud.haddock.cc","headers":{"User-Agent":["Mozilla/5.0 (Linux) mirall/2.6.4git (Nextcloud)"],"Accept":["*/*"],"X-Request-Id":["f4842097-4648-499e-a7dc-3ee08298abec"],"Connection":["Keep-Alive"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,*"]},"tls":{"resumed":false,"version":772,"ciphersuite":4865,"proto":"","proto_mutual":true,"server_name":"cloud.haddock.cc"}},"duration":0.001318633,"status":502,"err_id":"1dq4z2f2v","err_trace":"reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:380)"}

Here’s my post on the Caddy forums for reference: