Redirect loop on upgrade from 12.0.2 to 13.0.2 with nginx

Hello,
I recently migrated my Nextcloud installation from Nextcloud 12.0.2 with (php5.5-fpm + nginx 1.13.9) to (php-7.2-fpm + nginx 1.13.9). I followed the instructions described here. A redirection issue appeared.

Description of the issue

After logging in, an infinite redirection takes place, to https://cloud.server.com/index.php/apps/files/

I’m quite sure this is not a scheme issue (HTTP <-> HTTPS back and forth redirection), since I had no issue with Nextcloud 12

So far, I tried the following :

  • Googling the issue

  • Reading issues raised by other Nextcloud users on this forum

  • Fixing permissions on /usr/lib/php/* directories

But none of these helped.

Here is my nginx config :

 server {
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name  cloud.server.com;
        root html/nextcloud_13;

        error_log  logs/nextcloud/error.log;
        access_log logs/nextcloud/access.log;

        include /etc/nginx/conf/ssl.conf;

        location ~ \.php.* {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
         }

          fastcgi_pass 127.0.0.1:9000;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#         fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param HTTPS on;
     }
 }

location ~ /config {
    deny all;
}

location / {
rewrite ^/\.well-known/caldav /remote.php/dav permanent;
}       

}

Here is my config.php (which I copied from the previous Nextcloud folder)

<?php
$CONFIG = array (
  'instanceid' => 'xxx',
  'passwordsalt' => xxx',
  'secret' => 'xxx',
  'trusted_domains' => 
  array (
    0 => 'www.server.com',
    1 => 'cloud.server.com',
  ),
  'datadirectory' => '/home/nextcloud',
  'overwrite.cli.url' => 'https://www.server.com',
  'dbtype' => 'mysql',
  'version' => '13.0.2.1',
  'dbname' => 'nextclouddb',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'xxx',
  'dbpassword' => 'xxx',
  'installed' => true,
  'theme' => '',
  'maintenance' => false,
  'loglevel' => 2,
  'mail_smtpmode' => 'php',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_from_address' => 'nextcloud',
  'mail_domain' => 'server.com',
);

Any help is greatly appreciated.

I recommend to use the nginx configuration from the official documentation:
https://docs.nextcloud.com/server/13/admin_manual/installation/nginx.html

Thank you for your kind help. I tried replacing my nginx configuration with the official configuration as you suggested, but the problem is still here. In case that helps, here is the new nginx configuration

upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}

server {
listen 80;
listen [::]:80;
server_name cloud.server.com;
# enforce https
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name cloud.server.com;


# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
# add_header Strict-Transport-Security "max-age=15768000;
# includeSubDomains; preload;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;

# Path to the root of your installation
root html/nextcloud_13/;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;

location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}

# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;

# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;

location / {
rewrite ^ /index.php$uri;
}

location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}

location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[13]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}

location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}

# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=15778463";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
# add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}

location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}

Did you let nginx reload the configuration after changing it with
sudo nginx -s reload
?

Yes I restarted nginx. Just as a side note, reloading may be enough, you’re right.

You are using a relative path for the root directive. Maybe that works, but I’ve never seen that before. Can you try to use an absolute path?

I have tried changing the line you suggested to

# Path to the root of your installation                                         
root /etc/nginx/html/nextcloud_13/;

But I still get the same error after restarting nginx and clearing my browser cache.

That is really weird - your configuration is identically to mine and mine is working without any issues.
What do nginx-logs and nextcloud.log say?

I solved my problem. In fact, my apps/ folder did not contain the files application. I emptied the apps folder of my Nextcloud 13 installation. I fixed the issue by copying the files app from my previous Nextcloud 12 installation.

cd nextcloud_12/apps
cp -r dav ../../nextcloud_13/apps/

Thank you Bernie_O for your help !