How to Fix Common NextCloud Performance Issues

NextCloud 18 screenshotNextCloud is a PHP web application but it requires special performance tuning compared to other applications. The default PHP configuration values are not tailored for applications that require connections to be open for minutes (or hours) to facilitate large file uploads.

Getting NextCloud “up and running” may seem like a simple process, with all sorts of Bash installation scripts available on the Internet for installing NextCloud on a virtual or dedicated server. But an “out of the box” installation of NextCloud is not usually ready for production use.

Very basic functionality in NextCloud, such as uploading and downloading large files, can be broken without the administrator even being aware, if it is not tested prior to rolling out NextCloud to your organization’s users.

If your network architecture has a proxy or load balancer in front of the NextCloud app server(s), the web server and PHP timeouts should be checked on the NextCloud servers, in addition to connection timeouts on the load balancer.

Below we have listed some of the most common errors that are reported to NextCloud administrators by their users, and how you can troubleshoot to resolve them. We recommend trying these steps for intermediate to advanced users of Linux, keeping in mind to restart HAProxy, Nginx, or PHP-FPM after making each change.

If you require professional troubleshooting of NextCloud issues, or want a brand new instance of NextCloud set up correctly out of the gate, contact us for a quote. Our team consists of sysadmins and engineers who are experts in cloud architecture, networking and security, storage administration, and server tuning.

We have deployed NextCloud for end user organizations from individual users to hundreds or thousands of users. As 100% open source software, all of NextCloud’s capabilities including most “enterprise” features such as single sign on, LDAP/AD integration, role-based access controls, and file retention can be configured even in the NextCloud community edition.

Can’t upload large files > 512 MB to NextCloud (from browser)

– Are you using NextCloud behind any reverse proxies? Reverse proxies may include CloudFlare, cloud managed load balancers, or any load balancer. CloudFlare’s free tier imposes a 100 MB max upload size. Try disabling CloudFlare by “grey clouding” the DNS entry for your NextCloud instance.

If you must use CloudFlare or a similar reverse proxy, you will only be able to upload large file using the NextCloud desktop client, as the desktop client is configured to split files into chunks for uploading – which are then reassembled on the server-side.

Max upload sizes and connection timeouts are hard coded with cloud managed load balancers, so we recommend using a custom load balancer such as HAProxy instead. If using HAProxy, in the defaults or frontend section(s) of the haproxy.cfg file, the values should be set as follows.

timeout connect 30s
timeout client 2h
timeout server 2h

Add or modify these values in the php.ini and/or php-fpm.d/www.conf file (for PHP-FPM installations). The upload_max_size should always be <= post_max_size. You can set the values higher than 4GB if users will upload files larger than that through the web interface.

max_execution_time >= 300
max_input_time >= 300
memory_limit >= 512M
post_max_size >= 4GB
upload_max_filesize >= 4GB

Add or modify these directives in the ssl server block in your Nginx configuration for NextCloud. Setting the client_max_body_size to 0 means that uploads will not be limited by Nginx.

client_max_body_size 0;
fastcgi_buffers 64 4K;

Downloads of files from NextCloud fail at 1GB

Add or modify these directives in the ssl server block in your Nginx configuration for NextCloud. The fastcgi_max_temp_file_size defaults to 1GB – that is why downloads of large files fail at exactly 1GB.

proxy_buffering off;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
fastcgi_max_temp_file_size 0;

Can’t login to NextCloud (can’t submit or redirects back to login form)

– Make sure /var/lib/php/session is owned by the web server user. The ownership of this directory can sometimes be set to root:apache after upgrading PHP through the package repositories.

– CloudFlare’s Rocket Loader can conflict with the Content Security Policy (CSP) that is recommended for NextCloud in the official documentation. Disable Rocket Loader and other security or performance optimizations using a Page Rule.

– If you have multiple NextCloud app servers behind a load balancer, set up shared session storage in php.ini with a database or Redis session handler.

Web interface is very slow or encountering 503 Service Unavailable errors

– Enable memory caching for NextCloud with APCu, Memcached, or Redis. For a single-node NextCloud deployment, APCu is the simplest memory cache to configure. – – For a multi-node deployment, Redis should be used for distributed caching, in addition to Transactional File Locking (if not using NFSv3 or v4 with file locking enabled, or object storage) with two separate Redis databases using the 'dbindex' option.

– Configure cron processing for NextCloud in cron versus webcron mode in Settings > Administration > Basic settings. Add this line to /etc/crontab.

*/5 * * * * nginx php -f /var/www/nextcloud/cron.php

– Disable thumbnail generation by adding the following line to config/config.php in your NextCloud app folder.

'enable_previews' => false,