Locked into redirection loop at login

Nextcloud version (eg, 18.0.2): 19.0.3
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04.1
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.41
PHP version (eg, 7.1): 7.4.3

The issue you are facing:
When trying to login into my nextcloud at nextcloud.mydomain.de (https) I get redirected to the login page and the URL in the address bar changes to https://nextcloud.mydomain.de/index.php/login?redirect_url=/index.php/apps/files/
It happens with both admin and user accounts.

I do not recollect what might be the cause of this. My only guess goes toward a conflict of redirections, maybe between the certbot certificate (signed to mydomain.de and *.mydomain.de) and redirection rules in the various config files in /etc/apache2.

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

Steps to replicate it:

  1. Visit nextcloud.mydomain.de (http or https)
  2. Enter valid admin or user credentials, hit login button
  3. Land on login page again

The output of your Nextcloud log in Admin > Logging:

{"reqId":"*","level":2,"time":"2020-08-17T17:33:35+00:00","remoteAddr":"95.91.226.131","user":"--","app":"no app in context","method":"GET","url":"/","message":"Could not detect any host in http:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":""}
{"reqId":"*","level":2,"time":"2020-08-17T17:33:35+00:00","remoteAddr":"95.91.226.131","user":"--","app":"no app in context","method":"GET","url":"/","message":"Could not detect any host in https:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":""}
{"reqId":"*","level":3,"time":"2020-08-17T17:33:35+00:00","remoteAddr":"95.91.226.131","user":"--","app":"jsresourceloader","method":"GET","url":"/","message":"Could not find resource js/setup.js to load","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":""}
{"reqId":"*","level":3,"time":"2020-08-17T17:33:35+00:00","remoteAddr":"95.91.226.131","user":"--","app":"PHP","method":"GET","url":"/","message":"chmod(): No such file or directory at /var/www/nextcloud/lib/private/Log/File.php#86","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":""}
{"reqId":"*","level":3,"time":"2020-08-17T17:35:08+00:00","remoteAddr":"40.117.213.15","user":"--","app":"PHP","method":"GET","url":"/","message":"session_start(): A session had already been started - ignoring at /var/www/nextcloud/lib/private/Session/Internal.php#209","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299","version":""}
{"reqId":"*","level":2,"time":"2020-08-17T17:35:08+00:00","remoteAddr":"40.117.213.15","user":"--","app":"no app in context","method":"GET","url":"/","message":"Could not detect any host in http:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299","version":""}
{"reqId":"*","level":2,"time":"2020-08-17T17:35:08+00:00","remoteAddr":"40.117.213.15","user":"--","app":"no app in context","method":"GET","url":"/","message":"Could not detect any host in https:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299","version":""}
{"reqId":"*","level":3,"time":"2020-08-17T17:35:08+00:00","remoteAddr":"40.117.213.15","user":"--","app":"jsresourceloader","method":"GET","url":"/","message":"Could not find resource js/setup.js to load","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299","version":""}
{"reqId":"*","level":3,"time":"2020-08-17T17:36:59+00:00","remoteAddr":"95.91.226.131","user":"--","app":"PHP","method":"POST","url":"/index.php","message":"session_start(): A session had already been started - ignoring at /var/www/nextcloud/lib/private/Session/Internal.php#209","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":""}
{"reqId":"*","level":2,"time":"2020-08-17T17:36:59+00:00","remoteAddr":"95.91.226.131","user":"--","app":"no app in context","method":"POST","url":"/index.php","message":"Could not detect any host in http:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":""}
{"reqId":"*","level":2,"time":"2020-08-17T17:36:59+00:00","remoteAddr":"95.91.226.131","user":"--","app":"no app in context","method":"POST","url":"/index.php","message":"Could not detect any host in https:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":""}

(Why the log dates back to 17th August instead of today I don't know)

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

<?php
$CONFIG = array (
  'instanceid' => '*',
  'passwordsalt' => '*',
  'secret' => '*',
  'trusted_domains' =>
  array (
    0 => 'nextcloud.mydomain.de',
    1 => 'SERVER-IP',
  ),
  'datadirectory' => '/home/data/',
  'dbtype' => 'mysql',
  'version' => '19.0.3.1',
  'overwrite.cli.url' => 'https://nextcloud.mydomain.de',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '*',
  'dbpassword' => '*',
  'installed' => true,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
);

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

[06/Oct/2020:16:29:20 +0200] "GET / HTTP/1.1" 302 1555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
[06/Oct/2020:16:29:20 +0200] "GET /index.php/login HTTP/1.1" 200 5994 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
[06/Oct/2020:16:29:20 +0200] "GET /cron.php HTTP/1.1" 200 940 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
[06/Oct/2020:16:29:26 +0200] "POST /index.php/login HTTP/1.1" 303 1412 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
[06/Oct/2020:16:29:26 +0200] "GET /index.php/apps/files/ HTTP/1.1" 303 830 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
[06/Oct/2020:16:29:27 +0200] "GET /index.php/login?redirect_url=/index.php/apps/files/ HTTP/1.1" 200 6025 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
178.73.215.171 - - [06/Oct/2020:16:29:29 +0200] "GET / HTTP/1.0" 200 11239 "-" "-"
[The above entry seems unrelated to my login request]
[06/Oct/2020:16:29:27 +0200] "GET /cron.php HTTP/1.1" 200 940 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"

Hello,
have you found a solution?
I have the same error.

Unfortunately not. In the end I changed from apache to nginx and from mysql to mariadb and reinstalled nextcloud. It has been working since then.

I just experienced this strange redirect phenomenon when logging in both for my user and the admin user using Nextcloud 20.0.5 and Firefox 84.0.2. It worked again after clearing browser data.

What tipped me off was that login remained functional both in Chrome, and a Private Firefox window.

1 Like