NCP: reverse proxy configuration leads to too many redirects error

I setup the following docker container:

  • nextcloud
  • nextcloudpi
  • reverse-proxy
  • sharelatex (not important, just for testing)

I configured the reverse-proxy so that is redirects subdomains of my main domain to the other docker container. Its working well for nextcloud and sharelatex, but not for nextcloudpi. How do I configure it correctly?

nextcloudpi logs:

$ sudo docker logs nextcloudpi
Initializing empty volume..
stopping Cron...
cron: no process found
Stopping apache
httpd (no pid file) not running
Stopping PHP-fpm
Making /usr/local/etc/ncp-config.d persistent ...
Making /etc/services-enabled.d persistent ...
Making /etc/letsencrypt persistent ...
Making /etc/shadow persistent ...
Making /etc/cron.d persistent ...
Making /etc/cron.daily persistent ...
Making /etc/cron.hourly persistent ...
Making /etc/cron.weekly persistent ...
Making /usr/local/bin persistent ...
Making /etc/apache2 persistent ...
Starting PHP-fpm
Starting Apache
Starting mariaDB
2022-07-10  7:33:23 0 [Note] mysqld (mysqld 10.5.15-MariaDB-0+deb11u1) starting as process 109 ...
2022-07-10  7:33:23 0 [Warning] The parameter innodb_file_format is deprecated and has no effect. It may be removed in future releases. See https://mariadb.com/kb/en/library/xtradbinnodb-file-format/
2022-07-10  7:33:23 0 [Warning] The parameter innodb_buffer_pool_instances is deprecated and has no effect.
2022-07-10  7:33:23 0 [Note] InnoDB: Uses event mutexes
2022-07-10  7:33:23 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-07-10  7:33:23 0 [Note] InnoDB: Number of pools: 1
2022-07-10  7:33:23 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2022-07-10  7:33:23 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2022-07-10  7:33:23 0 [Note] InnoDB: Using Linux native AIO
2022-07-10  7:33:23 0 [Note] InnoDB: Initializing buffer pool, total size = 268435456, chunk size = 134217728
2022-07-10  7:33:23 0 [Note] InnoDB: Completed initialization of buffer pool
2022-07-10  7:33:23 0 [Note] InnoDB: 128 rollback segments are active.
2022-07-10  7:33:23 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-07-10  7:33:23 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-07-10  7:33:23 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-07-10  7:33:23 0 [Note] InnoDB: 10.5.15 started; log sequence number 1218587; transaction id 1841
2022-07-10  7:33:23 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-07-10  7:33:23 0 [Note] InnoDB: Loading buffer pool(s) from /data/database/ib_buffer_pool
2022-07-10  7:33:23 0 [Note] Server socket created on IP: '127.0.0.1'.
2022-07-10  7:33:23 0 [Note] Reading of all Master_info entries succeeded
2022-07-10  7:33:23 0 [Note] Added new Master_info '' to hash table
2022-07-10  7:33:23 0 [Note] mysqld: ready for connections.
Version: '10.5.15-MariaDB-0+deb11u1'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Debian 11
2022-07-10  7:33:24 0 [Note] InnoDB: Buffer pool(s) load completed at 220710  7:33:24
Starting Redis
Starting Cron
Starting Postfix
Provisioning
Provisioning Redis password
Updating NextCloud config with Redis password
Provisioning MariaDB password
Updating NextCloud config with MariaDB password
Running nc-limits
Using 6159691776B for PHP
Using 6 PHP threads
Using 2002898944 memory for the database
2022-07-10  7:33:26 0 [Note] mysqld (initiated by: root[root] @ localhost []): Normal shutdown
2022-07-10  7:33:26 0 [Note] Event Scheduler: Purging the queue. 0 events
2022-07-10  7:33:26 0 [Note] InnoDB: FTS optimize thread exiting.
2022-07-10  7:33:26 0 [Note] InnoDB: Starting shutdown...
2022-07-10  7:33:26 0 [Note] InnoDB: Dumping buffer pool(s) to /data/database/ib_buffer_pool
2022-07-10  7:33:26 0 [Note] InnoDB: Buffer pool(s) dump completed at 220710  7:33:26
2022-07-10  7:33:27 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2022-07-10  7:33:27 0 [Note] InnoDB: Shutdown completed; log sequence number 1218599; transaction id 1844
2022-07-10  7:33:27 0 [Note] mysqld: Shutdown complete

Stopping MariaDB database server: mariadbd.
Starting MariaDB database server: mariadbd.
Stopping redis-server: redis-server.
Starting redis-server: redis-server.
Starting notify_push daemon
Configuring Domain
System config value trusted_domains => 11 set to string 91.41.176.203
System config value trusted_domains => 1 set to string 172.21.0.7
System config value trusted_domains => 14 set to string dba6200a3c81
System config value trusted_domains => 6 set to string 192.168.103.34
Nextcloud version 23.0.2.1. NextCloudPi version v1.47.2
Init done

error messag ein chromium:

This page isn’t working cloud.bardhome.eu redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

config.php (censored some parts of course)

<?php
$CONFIG = array (
  'passwordsalt' => '**deleted**',
  'secret' => '**deleted**/',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    7 => 'nextcloudpi',
    5 => 'nextcloudpi.local',
    8 => 'nextcloudpi.lan',
    3 => 'nextcloudpi',
    11 => '91.41.176.203',
    1 => '172.21.0.7',
    14 => 'dba6200a3c81',
    6 => '192.168.103.34',
  ),
  'datadirectory' => '/data/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '23.0.2.1',
  'overwrite.cli.url' => 'https://nextcloudpi/',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'ncadmin',
  'dbpassword' => '**deleted**',
  'installed' => true,
  'instanceid' => 'oca6ngd07z8y',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
    'password' => '**deleted**',
  ),
  'tempdirectory' => '/var/www/nextcloud/data/tmp',
  'mail_smtpmode' => 'sendmail',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_from_address' => 'admin',
  'mail_domain' => 'ownyourbits.com',
  'preview_max_x' => '2048',
  'preview_max_y' => '2048',

 'preview_max_x' => '2048',
  'preview_max_y' => '2048',
  'jpeg_quality' => '60',
  'overwriteprotocol' => 'https',
);


reverse-proxy config:

 server {
            listen 443 ssl;
            listen [::]:443;
            include snippets/self-signed.conf;
            include snippets/ssl-params.conf;

            server_name cloud.bardhome.eu;

                location / {
                        proxy_read_timeout 1800;
                        proxy_connect_timeout 1800;
                        proxy_send_timeout 1800;
                        send_timeout 1800;

                        proxy_buffering                      off;
                        proxy_set_header Host                $http_host;
#                       proxy_set_header X-Real-IP           $remote_addr;
#                       proxy_set_header X-Forwarded-For     $proxy_add_x_forwarded_for;
                        proxy_set_header X-Forwarded-Proto   https;
#                       proxy_set_header Host $http_host;
                       client_max_body_size 25G;
                       proxy_pass http://nextcloudpi/;
                }
        }


push*
any hints here or suggestions to improve my question?

Especially the config.php is interesting to me. I link to posts which did not help:
phip1611 => many errors from the begining. Got it running after some time, but also had the “too many redirects” error.
This forum => no config.php. Not enough info for me to configure.

Not sure if I can help you. I use the ngnix reverse proy manager and it runs like a charm.
Have you added the lokal IP to the trusted proxies in the ncp panel?
Do you use any apps which are little bit complicated with proxies (talk, office)?

When I set the trusted proxies, it added this part to the config.php, but I still have the same error:

'trusted_proxies' =>
  array (
    0 => '192.168.103.34',
    2 => '127.0.0.1',
    1 => 'localhost',
  ),

I also tried the IP of the reverse proxy docker container (172.21.0.7) as trusted proxy, but it leads to the same error.
192.168.103.34 is the ip of the server where the docker container are running on.

ok I solved it the following way:

  1. Renamed config.php to config.php.backup
  2. go to the nextcloud dashboard (e.g. http://192.168.189.23 in your browser). Enter the passwords and database data from config.php.backup. Set new admin password.
  3. add the ip of the docker container host (so basically the ip of your server) to the trusted domains.

Here is my new autogenerated config.php:


<?php
$CONFIG = array (
  'instanceid' => 'asdh5345ju',
  'passwordsalt' => 'eregrgre43543hthr45uu4h',
  'secret' => 'KQJdasfasdfadsgrhreht',
  'trusted_domains' => 
  array (
    0 => '192.168.103.34:82',
    20 => 'kaese.eu',
    21 => 'kaese.spdns.eu',
    22 => 'cloud.kaese.eu',
  ),
  'datadirectory' => '/data/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '23.0.2.1',
  'overwrite.cli.url' => 'http://192.168.103.34:82',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'ncadmin',
  'dbpassword' => 'agrrgreggregre',
  'installed' => true,
);

Its just quite unfortunate that all my files and addons are then gone. So I will have to backup them and reinstall them when I try it on my productive system.