How to install and set up Nextcloud with NGINX
Running Nextcloud with NGINX allows for efficient use of system resources along with flexible deployment options. To set it up properly, you’ll need a compatible system environment and the right configuration. A few specific adjustments are also required for smooth integration with NGINX.
What is NGINX and why pair it with Nextcloud?
NGINX is an open-source-based web server software that can also serve as a reverse proxy server, load balancer and HTTP cache. Originally developed by Russian software engineer Igor Sysoev, NGINX is distributed under the BSD license (BSD is a Unix variant).
NGINX is designed to handle a large number of connections simultaneously. To do this, the software uses an event-driven, non-blocking architecture. Unlike traditional web servers that spawn a new process or thread for each connection, NGINX runs a master process alongside multiple worker processes. The master handles configuration, while the workers process incoming client requests.
Pairing Nextcloud with NGINX offers several key benefits for high-performance environments, including:
- Efficient resource usage: NGINX can handle multiple connections at once, with minimal resource consumption.
- Excellent scalability: NGINX supports flexible load balancing and is easily scalable by adding additional servers.
- Highly customisable architecture: Thanks to its modular structure, NGINX can be adapted to suit a wide range of scenarios.
- Reliable performance under heavy server load: Even when the server is under heavy use, NGINX is reliable, keeping your services continuously available.
Since Nextcloud only officially supports Apache 2.x as its web server, there is no official support for NGINX. Running Nextcloud with NGINX is therefore best suited to users with experience in web server configuration.
What are the requirements for running Nextcloud with NGINX?
To run Nextcloud on NGINX, you’ll need a server running Ubuntu, Debian, or another compatible system. The server should have at least 4 GB of RAM and two CPUs. For larger setups with multiple Nextcloud apps, more memory and CPU cores are strongly recommended. You’ll also need adequate storage space for data and backups.
For installation, you’ll also need a compatible database like MySQL or MariaDB, as well as the PHP scripting language (minimum version 8.1, version 8.3 recommended). The database is used to store user data and plugin data, as well as file metadata. PHP is required to run Nextcloud’s core functions. You’ll also need an account with admin rights to install the software.
- Keep your data safe with industry-leading security
- Save time on updates and maintenance
- Easily add apps and online office tools
How to install Nextcloud with NGINX
Some essential preparations should be completed before installing Nextcloud. This guide assumes an Ubuntu server where the system and all required dependencies are already in place. These include NGINX as the web server, MySQL as the database, and PHP 8.3 with all the necessary extensions.
We have also installed Certbot for easy SSL certificate setup with Let’s Encrypt. We also assume you have a domain set up so you can access Nextcloud via a URL rather than an IP address.
You can also follow our tutorials for learning how to install Nextcloud on Ubuntu 22.04, set up Nextcloud on Kubernetes or install Nextcloud on Debian 12.
How to download and unpack Nextcloud
Start by creating a folder called “nextcloud” in your home directory to store the installation files. While this can be done manually via the Nextcloud changelog, it’s quicker to use the following Curl command:
mkdir ~/nextcloud && cd ~/nextcloud
curl --output nextcloud.zip https://download.nextcloud.com/server/releases/nextcloud-30.0.5.zipIf you’re installing a different version of Nextcloud, make sure to update the URL accordingly.
Then unzip the file, move it to the web root ./var/www and set the file permissions:
unzip nextcloud.zip && sudo mv nextcloud /var/www/ && sudo chown -R www-data:www-data /var/www/nextcloudHow to set up the database
To set up the MySQL database, run the sudo command sudo mysql_secure_installation. Type “y” to set your root password (VALIDATE PASSWORD) and choose “2” for a strong password (STRONG), which you can then set up. Press “y” to confirm the password, then press “y” again to remove anonymous users, disable remote logins, remove the test database, and reload the privilege tables.
Then follow these steps:
- Log in as the root user using sudo mysql -u root -p.
- Create the database using: create database nextcloud;.
- Create the user using: create user 'nextcloud'@'localhost' identified by <new_password>;.
- Grant permissions using: grant all privileges on nextcloud.* to 'nextcloud'@'localhost';.
- Finally, update the privileges using flush privileges;and exit the database console usingexit.
Once the database has successfully been set up, you need to add the credentials (DB_NAME, DB_USER, DB_PASSWORD) to the Nextcloud configuration file. Open the file ./var/www/nextcloud/config/config.php and add the relevant entries:
'dbtype' => 'mysql',
'dbname' => 'nextcloud',
'dbuser' => 'nextcloud',
'dbpassword' => '<your_password>',
'dbhost' => 'localhost',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,- Unlimited traffic and up to 1 Gbit/s bandwidth
- Fast SSD NVMe storage
- Free Plesk Web Host Edition
How to disable NGINX’s default configuration
Before integrating Nextcloud into NGINX, you need to make sure no other configuration files override the Nextcloud installation. By default, there may still be a default configuration file in ./etc/nginx/sites-enabled/ that could interfere with your set up. Remove it using:
sudo rm /etc/nginx/sites-enabled/defaultThen activate your custom configuration with this command:
sudo ln -s /etc/nginx/sites-available/exampledomain.co.uk /etc/nginx/sites-enabled/How to configure the NGINX server
To configure NGINX as the web server, a domain should already be set up and linked to the server’s IP. Make sure the DNS is also correctly set up. Create a new NGINX config file in the sites-available directory using:
sudo touch /etc/nginx/sites-available/exampledomain.co.uk(We used exampledomain.co.uk as the URL.)
Open the config file in a text editor (such as Vim) using:
sudo vim /etc/nginx/sites-available/exampledomain.co.ukInsert the code block from the ‘Nextcloud in a subdir of the NGINX webroots’ section of the Nextcloud NGINX config documentation.
Since the HTTPS certificate will be added with Certbot, remove any SSL-related lines from the NGINX config file. Certbot will handle these automatically.
How to set up an SSL certificate with Certbot
To run Nextcloud over a secure HTTPS connection, you need to set up an SSL certificate, in this case from Let’s Encrypt. To begin with, configure the firewall to allow HTTPS and SSH connections using the following sudo commands:
sudo ufw allow 'Nginx Full'
sudo ufw allow 'OpenSSH'Next, enable the firewall with sudo ufw enable and check with sudo ufw status to ensure the connections are allowed. Then you can create the SSL certificate using Certbot:
sudo certbot --nginx -d exampledomain.co.ukFollow the prompts to provide your email address for certificate renewals and to accept the terms of service. Choose option 2 to automatically redirect all HTTP requests to HTTPS. Certbot saves the certificate files in the .etc/letsencrypt/live/exampledomain.co.uk/ directory. The file fullchain.pem contains the SSL certificate, and privkey.pem contains the private key. You need to add them to your NGINX configuration file:
ssl_certificate /etc/letsencrypt/live/exampledomain.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/exampledomain.co.uk/privkey.pem;Since Certbot modified the configuration file, you need to add the ssl attribute between 443 and http2 again. The block should look like this:
server { 
    listen 443 ssl http2; 
    listen [::]:443 ssl http2; 
    server_name exampledomain.co.uk;
}How to restart services and access Nextcloud
For the changes to take effect, you need to reload the PHP-FPM and NGINX services:
sudo systemctl reload php8.3-fpm.service
sudo systemctl reload nginx.serviceNow, open your domain in the browser - exampledomain.co.uk in our case. If everything has been configured correctly, the Nextcloud welcome page should appear.
If Nextcloud doesn’t load, it may be because your domain isn’t listed as a Trusted Domain in config.php. Add it there to fix the issue.

