Failed to migrate docker instance to version 24

Hi there.

I have had a dockerized nextcloud 22 in a docker compose setup with a caddy reverse proxy and everythig worked fine. Then, I wanted to update to version 24, but this failed as (what I did not know) one can only update to the next major version without skipping.
So, the nextcoud data (in a volume) was corrupted as it was tagged as “version 24” now, but nextcloud 24 did not start but stayed in maintenance mode. Rolling back to version 22 was also not possible, as the nextcloud then says “my data and config folder are version 24 this is newer than me” and does also not start.
I created a whole new folder and docker setup with nextcloud 24 and that worked. Then, I wanted to do a step by step migration of the data from the old instance to the new one.
First, I wanted to get my installed apps back and after restarting (and adding my domain to the trusted domains in config.php) it suddenly happed, that I could access my nextcloud anymore.
It always says “too many redirects”. I think this is because it wants to redirect to HTTPS but the reverse proxy is commutication via http.

All my research of on the internet failed and I dont know, how to change my setup to get this to work. It is a little bit of a chaos now and I am not moving forward or backwards anymore. Here is my current setup:

Caddyfile (basically unchanged over the course of the migration except for some tries to set headers here and there)

cloud.mydomain.com {
	header Strict-Transport-Security max-age=15552000;
	
	reverse_proxy localhost:8080
}

docker-compose.yml of the new instance. This is the exact same file as for the old instance but I changed the volume directory for the database and the data directorys

version: "3.9"
services:
  db:
    image: postgres
    restart: always
    volumes:
      - ./db:/var/lib/postgresql/data:rw
    environment:
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user
  redis-cache:
    image: redis:alpine
    command: "redis-server --requirepass ${REDIS_HOST_PASSWORD}"
    restart: unless-stopped
    environment:
      - REDIS_HOST_PASSWORD=/run/secrets/redis_password
    secrets:
      - redis_password
  nextcloud:
    image: nextcloud:24
    restart: always
    ports:
      - "8080:80"
    volumes:
      - ./nextcloud:/var/www/html
      #- ./apps:/var/www/html/custom_apps
      #- ./config:/var/www/html/config
      - /mnt/storage-box-1/nextcloud-new/data/data:/var/www/html/data
      #- ./data-temp:/var/www/html/data
      #- ./theme:/var/www/html/themes/custom
      #- ./php-config:/usr/local/etc/php-test
    environment:
      - REDIS_HOST_PASSWORD=/run/secrets/redis_password
      - POSTGRES_HOST=db
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
      - NEXTCLOUD_ADMIN_PASSWORD_FILE=/run/secrets/nextcloud_admin_password
      - NEXTCLOUD_ADMIN_USER_FILE=/run/secrets/nextcloud_admin_user
    depends_on:
      - redis-cache
      - db
    secrets:
      - nextcloud_admin_password
      - nextcloud_admin_user
      - postgres_db
      - postgres_password
      - postgres_user

volumes:
  db:
  nextcloud:

secrets:
  redis_password:
    file: ./secrets/redis_password.txt
  postgres_db:
    file: ./secrets/postgres_db.txt
  postgres_user:
    file: ./secrets/postgres_user.txt
  postgres_password:
    file: ./secrets/postgres_password.txt
  nextcloud_admin_password:
    file: ./secrets/nextcloud_admin_password.txt
  nextcloud_admin_user:
    file: ./secrets/nextcloud_admin_user.txt

config.php in the new instance:

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'redis-cache',
    'port' => '6379',
    'dbindex' => 0,
    'password' => 'censored',
    'timeout' => 1.6,
  ),
  '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,
    ),
  ),
  'passwordsalt' => 'censored',
  'secret' => 'censored',
  'trusted_domains' => 
  array (
    0 => 'cloud.mydomain.com',
    1 => 'cloud-maintenance.mydomain.com'
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'pgsql',
  'version' => '24.0.2.1',
  'overwrite.cli.url' => 'https://cloud.mydomain.com',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'oc_admin',
  'dbpassword' => 'censored',
  'installed' => true,
  'instanceid' => 'censored',
  'default_phone_region' => 'DE',
);

I hope, someone can help my. If I should post certain logs, please tell me.

The safest thing would be to restore from your last backup before the upgrade and go to version 23 first.