Timeouts and very slow connection between Apache reverse proxy and Nextcloud instance

Nextcloud version: 15.0.10
Operating system and version: Debian 9
Apache or nginx version: Apache/2.4.29 (Ubuntu 18.0.4 LTS)
PHP version: PHP 7.0.33-0+deb9u3

The issue you are facing:
Timeouts or very slow connection between Apache Reverse Proxy and Nextcloud. Both are running on different VMs in a private cloud environment. The Apache VM has an external IP adress while Apache and Nextcloud communicate over their private IPs. After running perfectly fine for a few weeks it started to get very slow some hours ago. It runs fine for a few minutes, then gets very slow again.
We’re not sure if our cloud provider is having problems (they’re stating they’re not, but in our experience this isn’t that reliable) or if our configuration is wrong.
I was experimenting with HSTS earlier today, maybe this could be the cause?

Steps to replicate it:

  1. Connect to Nextcloud via URL
  2. Very long connection times in browser network view (20000 ms plus)
  3. Errors in Apache log.

Apache vhost configuration:

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin xy
                ServerName xy

                DocumentRoot /var/www/html


                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on

                SSLCertificateFile /etc/apache2/ssl.crt/wildcard.domain.de-chain.crt
                SSLCertificateKeyFile /etc/ssl/private/wildcard.domain.de.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

                SSLProxyEngine on
                SSLProxyProtocol +all
                SSLProxyCipherSuite ALL
                SSLProxyCheckPeerName off
                SSLProxyCheckPeerCN off
                SSLProxyCheckPeerExpire off

                ProxyPass                       /       http://172.18.0.81/ retry=1 acquire=3000 timeout=600 Keepalive=On
                ProxyPassReverse                /       http://172.18.0.81/
                ProxyPassReverseCookiePath      /       /

        </VirtualHost>
</IfModule>

The output of your Nextcloud log in Admin > Logging:

{"reqId":"lc4NWq16dY7oZy1EGglk","level":3,"time":"2019-09-05T12:56:53+00:00","remoteAddr":"172.18.0.21","user":"--","app":"PHP","method":"GET","url":"\/cron.php","message":"Undefined index: all at \/var\/www\/nextcloud\/apps\/files_versions\/lib\/Storage.php#779","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko\/20100101 Firefox\/70.0","version":"15.0.10.0"}
{"reqId":"lc4NWq16dY7oZy1EGglk","level":3,"time":"2019-09-05T12:56:53+00:00","remoteAddr":"172.18.0.21","user":"--","app":"PHP","method":"GET","url":"\/cron.php","message":"Undefined index: by_file at \/var\/www\/nextcloud\/apps\/files_versions\/lib\/Storage.php#781","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko\/20100101 Firefox\/70.0","version":"15.0.10.0"}
{"reqId":"lc4NWq16dY7oZy1EGglk","level":3,"time":"2019-09-05T12:56:53+00:00","remoteAddr":"172.18.0.21","user":"--","app":"PHP","method":"GET","url":"\/cron.php","message":"Invalid argument supplied for foreach() at \/var\/www\/nextcloud\/apps\/files_versions\/lib\/Storage.php#781","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko\/20100101 Firefox\/70.0","version":"15.0.10.0"}
{"reqId":"lc4NWq16dY7oZy1EGglk","level":3,"time":"2019-09-05T12:56:53+00:00","remoteAddr":"172.18.0.21","user":"--","app":"PHP","method":"GET","url":"\/cron.php","message":"ksort() expects parameter 1 to be array, null given at \/var\/www\/nextcloud\/apps\/files_versions\/lib\/Storage.php#805","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko\/20100101 Firefox\/70.0","version":"15.0.10.0"}
{"reqId":"lc4NWq16dY7oZy1EGglk","level":3,"time":"2019-09-05T12:56:53+00:00","remoteAddr":"172.18.0.21","user":"--","app":"PHP","method":"GET","url":"\/cron.php","message":"reset() expects parameter 1 to be array, null given at \/var\/www\/nextcloud\/apps\/files_versions\/lib\/Storage.php#806","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko\/20100101 Firefox\/70.0","version":"15.0.10.0"}

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 => '172.18.0.81',
  ),
  'datadirectory' => '/srv/data/',
  'dbtype' => 'mysql',
  'version' => '15.0.10.0',
  'dbname' => 'nextclouddb',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => '-',
  'installed' => true,
  'proxy' => 'http://172.18.0.250:3128/',
  'mysql.utf8mb4' => true,
  'maintenance' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'skeletondirectory' => '',
  'overwritehost' => 'portal.domain.de',
  'overwriteprotocol' => 'https',
  'overwritewebroot' => '/',
  'overwritecondaddr' => '^172.18.0.21$',
  'overwrite.cli.url' => 'http://172.18.0.81',
  'updater.release.channel' => 'production',
  'loglevel' => 2,
);

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

[Thu Sep 05 14:17:51.983927 2019] [proxy:error] [pid 7684:tid 139741710243584] [client :55684] AH00898: Error reading from remote server returned by /index.php/apps/files/
[Thu Sep 05 14:17:51.983938 2019] [proxy:error] [pid 7685:tid 139741676672768] [client :48897] AH00898: Error reading from remote server returned by /index.php/apps/files/
[Thu Sep 05 14:17:51.986519 2019] [proxy_http:error] [pid 7685:tid 139740787504896] (20014)Internal error (specific information not available): [client :29655] AH01102: error reading status line from remote server 172.18.0.81:80
[Thu Sep 05 14:17:51.986528 2019] [proxy_http:error] [pid 7685:tid 139741693458176] (20014)Internal error (specific information not available): [client :36214] AH01102: error reading status line from remote server 172.18.0.81:80

I now cloned the instance and am accessing it without a proxy directly over VPN. The behaviour is the same. I’m completely confused here.

What does your load average look like on them?

There’s no load at all. So that was pointing to internal Nextcloud errors. After checking everything else we disabled the Log Reader addon and that seems to have done the trick. Our log file was never cleaned since April 2019 and was 31 mb big. I can’t imagine that having this big impact and why it was fine since a few days ago, but now it is running again.

Nextcloud was slow again. Then I made the connection. Non admin users were never slow. Admin users were slow. I noticed that docs.nextloud.com was very slow or not reachable for some while now.

What is actually the cause isn’t the log reader, but the Nextcloud notifications app that checks for Nextcloud updates. Apparently it breaks the whole Nextcloud web ui when it can’t reach Nextcloud’s servers.

This is very irritating, to put it mildly…

I had the same experience and had the thought that maybe the issue was related to the nextcloud.com. I had a very slow NC but other users did not notice anything. Looked for errors everywhere and finally gave up and am reinstalling. But what if you are right? Maybe I did this unnecessarily?

I had the exact same issue in another instance, so I think a reinstallation won’t solve this. I would be interested in your experience with this issue.

Reinstallation fails repeatedly. I use the scripts by c.rieger which use to work very well. I realised to late what you mentioned about nonadmin users having no problems. Panicked and started solving issues that created new. Finally decided to reinstall from scratch but this did not work out. I have an installation running locally on my NAS which may save me for the most important functions.

My observation:
Very slow inlogging and function as admin. As ordinary user no problems. I changed the status for an ordinary user to admin and observed same slow inlogg and function. I deactivated Update notification and got back the normal speed. And doc.nextcloud.com is down again…
So the impression for now is that this issue is related to the Update notification app.