Nextcloud Server Ubuntu 20.04
Difficulty: Advanced
In my pursuit to find a self-hosted replacement for my current cloud based providers such as OneNote, Google Drive, Photos, Calendar, and Contacts i've decided to setup a Nextcloud server. The server will be responsible for hosting and syncing my documents, photos, and other important day to day data between my devices. The server features a fully qualified domain name, Nginx reverse proxy, SSL encryption, 2FA, Android connectivity, and VNC for remote maintenance.
Requirements (Local Connection)
- A computer to use as a server
Optional Requirements (Internet Connection)
Access to your router's interface.
A static IP and domain name or dynamicDNS.
3OJNXJUSMQIMFBK47PNHYRMMKU2ISGBN
Local Cloud Setup
Nextcloud Virtual Machine
For the host operating system I decided to install Ubuntu 20.04 because it supports automatic updates but you can use whatever operating system you prefer.
Once the host machine has a fresh operating system installed, download and install VirtualBox or your preferred virtualization software and download the latest Ubuntu Server Image (Option 2).
Once the virtualization software is installed create a new virtual machine for the Nextcloud server. Setting the VM's hard drive to dynamically allocated and limiting the size to whatever space is available on the physical hard drive at the time subtracting ~20gb for the host operating system.
After creating the virtual machine go into the network settings and set the mode to bridged. This sets the machine as an independent host on the network allowing visibility.
Nextcloud Server Setup
Start up the nextcloud server and select the ubuntu server image when prompted for a startup disk. This will load up the ubuntu server image and begin the installation process. The only extra step to do during the installation is to select the Nextcloud snap when prompted with the list of commonly installed snaps.
Setting a Static IP for the VM
To set a static IP on the virtual machine start it up and run the following command to install net-tools.
Once net-tools is installed run ifconfig
and note down the current IP address of the virtual machine.
Next we will modify the netplan .yaml file.
Modifying the file to appear as follows (replacing [ip-address] and [gateway]):
Ctrl-X, Y, Enter to save and exit. Then run:
Remote Maintenance
RealVNC Server Setup
Download and install RealVNC Server to the host machine.
RealVNC Viewer Setup
Download and install RealVNC Viewer to your mobile or desktop PC to access your server remotely.
RealVNC 2-Factor Authentication
Install FreeOTP+ or your chosen 2FA code generator from the Playstore.
Once your 2FA application is ready, go to the RealVNC website, sign in, and setup 2FA.
Exposing Server to the Internet
NOTE: If you are only configuring Nextcloud for a local network you can stop here. To access the server type the Nextcloud virtual machine's IP address in a browser and follow the setup guide.NginX Reverse Proxy Virtual Machine
Create a new virtual machine for the NginX Reverse Proxy. Set it up the same as the Nextcloud server: hard drive dynamically allocated with a maximum of 8gb and the network mode to bridged.
Reverse Proxy Server Setup
Start up the reverse proxy server and go through the motions of installing ubuntu server, this time not selecting any snaps when prompted. Once installation is complete login and set a static IP for the VM. Refer to the Nextcloud static IP setup for guidance.
Next install NginX with
Once NginX is installed create a config file for your domain (substituting [your-domain.url] as needed)
and edit it to appear as follows (substituting [your-domain.url] and [your-nextcloud-ip] as needed):
NOTE: This configuration file is designed for a HTTPS connection and will not function correctly until SSL encryption has been configured.
Port Forwarding
In your router’s settings, configure port 80 to forward all traffic to the NginX server and port 443 to forward TCP traffic to the NginX server. For additional help please refer to your router's online manual.
Static IP or Dynamic DNS
Option 1: Static IP & Domain Name
This option requires that your internet service provider is delegating a static IP to your internet connection. This usually comes default on business lines and can be an optional extra for home connections. It additionally requires the purchase or ownership of a fully qualified domain name.
Configure A records in your domain's DNS configuration portal to point at your public static IP address. For help finding your public IP address click here.
Option 2: Dynamic DNS
Free DynamicDNS services such as NoIP are available and may provide a suitable replacement for a domain name and static IP.
This option is by no means ideal but can be a suitable work around for an environment without access to the requirements for the first solution.
Securing the Server
Enable Firewall
Enable UFW on the Host, Nextcloud, and NginX server forwarding all traffic on port 80 and all TCP traffic on 443.
SSL Encryption
The last step that should really be done if the nextcloud will be accessed over the internet is to set up SSL encryption so that the server can be accessed through HTTPS. This will ensure that your files etc will be encrypted en route to and from the server though not on the server, which is fine since an account with a password is required to access it.
This is actually pretty easy to do thanks to Let's Encrypt. Ensure port 443 is forwarding in your router's configuration as that's the port used for SSL.
The certificates need to be set up on the nginx server, because that will be the terminal for ssl connections. So log into the NginX server and install Let's Encrypt's certbot by typing:
Once certbot is installed, create a config file for NginX (substituting [your-domain.url] as needed).
Install the proxy's config file (ensure to type full pathing or the link will fail).
Finally, restart nginx
Automatic Certificate Renewal
The SSL certificates expire every 90 days, but they can be easily and non-interactively renewed with
So just set up a cron job to do this every other month or so.
Adding the line
Which will automatically renew the certificates at midnight on the first of every other month.
Nextcloud 2-Factor Authentication
Login to your Nextcloud instance, click your profile at the top right and select Apps. Go to Security and download and enable Two-Factor TOTP Provider. Once the application is installed, go to Settings -> Security -> Enable TOTP Use the same authenticator you installed for RealVNC to configure 2FA for your Nextcloud server.
Android Connectivity
Nextcloud App Code
Navigate to your Nextcloud portal, go to Settings -> Personal -> Security. Scroll to the bottom of the page and type the name of the app you would like to grant access to. Click create new app password. Go back to the application you want to connect to your Nextcloud server, type in your username and the 29 character one time app password.
Calendar, Contact, and Task Syncronization Client
Install DAVx⁵ from the Playstore.
Once DAVx⁵ is installed, login to the app using a Nextcloud app code and allow the permissions you require. Once the app is finished configuring it will automatically sync all of your calendar events, contacts, and tasks with the phone's system apps.
Recommended Applications
A list of useful open source Android applications that extend the usability of the Nextcloud server.
- Nextcloud Syncronization Client available on the Playstore
- Joplin Notes available on the Playstore
- Simple Calendar Pro available on the Playstore