Help Reverse Proxy with Nextcloud!

Hey !

I have a problem with setting up a reverse proxy, I think it must be a small error but I don’t see where it comes from…

  • I have a server with an Apache reverse proxy.
  • It proxies to the server which carries nextcloud but I have a redirection loop (ERR_TOO_MANY_REDIRECTS)
  • I would like to point out that it worked very well without the reverse proxy !

Nextcloud version : 27.1.7.2
OS : Ubuntu 22.04
Apache : 2.4.52
PHP version : 8.1.2-1ubuntu2.15

This is what I did :

Apache reverse proxy conf:

<VirtualHost *:80>
    ServerName cloud.xxx.fr

    Redirect permanent / https://cloud.xxx.fr/
</VirtualHost>

<VirtualHost *:443>
    ServerName cloud.xxx.fr

     SSLEngine on
     SSLCertificateFile   /etc/letsencrypt/live/cloud.xxx.fr/fullchain.pem
     SSLCertificateKeyFile /etc/letsencrypt/live/cloud.xxx.fr/privkey.pem

    <Location />
        ProxyPass "http://192.168.1.194/"
        ProxyPassReverse "http://192.168.1.194/"
        ProxyPreserveHost On
        RequestHeader set X-Forwarded-Proto "https"
    </Location>

</VirtualHost>

Apache nextcloud conf :

<Directory /var/www/nextcloud/>
   Require all granted
   AllowOverride All
   Options FollowSymLinks MultiViews

   <IfModule mod_dav.c>
      Dav off
   </IfModule>
</Directory>

<VirtualHost *:80>
   ServerName cloud.xxx.fr
   DocumentRoot /var/www/nextcloud
   Alias / "/var/www/nextcloud/"

   Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"

   <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteRule ^/\.well-known/carddav http://%{SERVER_NAME}/remote.php/dav [R=301,L]
     RewriteRule ^/\.well-known/caldav http://%{SERVER_NAME}/remote.php/dav [R=301,L]
     RewriteRule ^/\.well-known/webfinger http://%{SERVER_NAME}/index.php/.well-known/webfinger [R=301,L]
     RewriteRule ^/\.well-known/nodeinfo http://%{SERVER_NAME}/index.php/.well-known/nodeinfo [R=301,L]
   </IfModule>

  Options -Indexes

  AllowEncodedSlashes NoDecode

</VirtualHost>

Nextcloud conf :

?php
$CONFIG = array (
  'instanceid' => 'xxxx',
  'passwordsalt' => 'xxxxxx',
  'secret' => 'xxxxxxx',
  'trusted_domains' => 
  array (
    0 => '192.168.1.194',
    1 => 'cloud.xxx.fr',
  ),
  'trusted_proxies'   => ['192.168.1.85'],
  'overwritehost'     => 'cloud.xxx.fr',
  'overwriteprotocol' => 'https',
  'overwritewebroot'  => '/',
  'overwritecondaddr' => '^192\.168\.0\.85$',
  'overwrite.cli.url' => 'https://cloud.xxx.fr/',
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '27.1.7.2',
  'overwrite.cli.url' => 'https://cloud.xxx.fr',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'mat',
  'dbpassword' => 'xxxxxxx',
  'installed' => true,
  'maintenance' => false,
  'updater.secret' => 'xxxxxxxxx',
  'theme' => '',
  'loglevel' => 2,
);

If you know where this might come from, help would be greatly appreciated :grinning: