Too many redirects on login page

[/details]

Nextcloud version: 18.0.7
Operating system and version: Debian GNU/Linux 10 in Docker image
Apache or nginx version: Apache/2.4.38 (Debian)
PHP version: 7.3.21

The issue you are facing:

recent actions done:
I recently checked for issues in the NC admin zone and I did fixing missing indexes on tables and the swtich to utf8mb4 with the occ cli commands.
Afterwards I set up my docker-compose.yml to incorporate redis to manage the memory caching. Verified and caching in redis worked fine
These actions can have to do with my issue, thus mentioning them.

The main issue is a TOO_MANY_REDIRECTS failure when visiting the root nextcloud address https://nc.—.eu/. Server tries to redirect to the login page, but after several attempts (see apache log below) it fails with the “Site isn’t redirecting properly” message.

I tried:
curl - v https://nc.----.eu/
and get

*   Trying --.-.--.---...
* TCP_NODELAY set
* Connected to nc.----.eu (---.---.---.--- port 80 (#0)
> GET / HTTP/1.1
> Host: nc.-----.eu
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Thu, 09 Sep 2021 10:11:09 GMT
< Content-Type: text/html
< Content-Length: 162
< Connection: keep-alive
< Location: https://nc.----.eu
< 
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host nc.-----.eu left intact

However visiting the
.../index.php/login
works and allows logging in. Afterwards the successfull login tries to redirect back to the root path and I guess to the /index.php/apps/files path, but fails with same error.
Trying to visit
.../index.php/apps/files
shows the appropriate page and all the further navigation works as usual.
The redirect problem is affecting the login part only, as much as I realized.

My first suspicion was redis, which has never been used before and which is managing the sessions. But after reverting the config back to original state (without redis) the problem persists.

The .htaccess part as the nginx reverse proxy as well were untouched. I use it for other severs too which work fine.
The files read write permission is verified.

Other Android Nextcloud clients as well as my Thunderbird mail client connected to the DAV still work and sync data. This redirection issue has only to do with browser requests.

My best guess and according to most references from google searches lead to sessions, cookies or the database data integrity, which eventually could cause this. But there is nothing more in the logs saying about access, read, writing errors or other issues.

I really appreciate hints, where to look next.

How can this redirection issue by traced down?

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

The output of your Nextcloud log in Admin > Logging:
nextcloud.log does not contain any reference to the redirecting problem

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

$CONFIG = array (
  'auth.bruteforce.protection.enabled' => true,
  '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' => '------',
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '18.0.7.1',
  'appstoreenabled' => true,
  'writable_appsdir' => false,
  'dbname' => '------',
  'dbhost' => 'nextclouddb',
  'dbtableprefix' => 'oc_',
  'dbuser' => '------',
  'dbpassword' => '------',
  'installed' => true,
  'forcessl' => false,
  'theme' => '',
  'maintenance' => false,
  'trusted_domains' => 
  array (
    0 => '------',
    1 => '------',
  ),
  'trusted_proxies' => 
  array (
    0 => '172.25.0.4',
  ),
  'secret' => '------',
  'share_folder' => '/Shared',
  'loglevel' => 0,
  'trashbin_retention_obligation' => 'auto',
  'filelocking.enabled' => true,
  'overwrite.cli.url' => '/',
  'mail_from_address' => '',
  'mail_smtpmode' => '',
  'mail_sendmailmode' => '',
  'mail_domain' => '',
  'mail_smtpauthtype' => '',
  'mail_smtphost' => '',
  'mail_smtpport' => '',
  'mail_smtpsecure' => '',
  'mail_smtpauth' => 1,
  'mail_smtpname' => '',
  'mail_smtppassword' => '',
  'mysql.utf8mb4' => false,
);

The output of your Apache log in docker logs for the nextcloud container:

172.25.0.5 - - [09/Sep/2021:09:44:58 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
172.25.0.5 - - [09/Sep/2021:09:44:59 +0000] "GET / HTTP/1.0" 302 921 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"

Ok, resolved.

The infinite redirect was caused by the nginx proxy setting. It is reverse proxying to the docker container via http, but communicates via https with clients. The http scheme from outside is permanently redirected via 301 respnse to https…

After setting the correct header options for nginx according to this instructions
https://www.cyberciti.biz/faq/linux-unix-nginx-redirect-all-http-to-https/

...
add_header           Front-End-Https    on;
add_header Strict-Transport-Security "max-age=2592000; includeSubdomains";
proxy_set_header Host $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 $scheme;
...

and restarting nginx the NC login works!

1 Like