KB450427 - Nextcloud with Nginx Proxy Manager on Ubuntu 20.04
Posted on June 25, 2021 by smacphee
- This guide will cover the process to setup Nextcloud as an internet facing application with an SSL certificate tied to a domain.
- Ubuntu 20.04 installed and running with all 45Drives scripts
- A registered or otherwise hosted domain
- Ports 80, and 443 port forwarded on your router
- A DNS record from your domain to your public IP address
- The first step in this process is getting docker engine and docker compose installed to do so we will need to first issue the below commands:
sudo apt-get install \
- We then need Dockers GPG key which can be downloaded with the following command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- We will now setup the Stable repository for docker
"deb https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- We can now install docker engine
apt-get install docker-ce docker-ce-cli containerd.io
- Now that docker engine is installed we can install docker compose, this can be done with the below commands:
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- We can confirm a successful docker compose installation by checking for our version with the following command:
- We will now create a new directory called /opt/nextcloud, inside this directory we will also make a .yml file called docker-compose.yml
- copy paste the following text into the docker-compose.yml file Make sure to replace the placeholder passwords
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
- We will also need to create a file in the same directory called Dockerfile
- Add the following text into Dockerfile
RUN apt-get update && apt-get install -y bash
RUN apt install smbclient -y bash
- We can now run our docker file which will install Nextcloud, Ngnix, and the necessary databases
docker-compose up -d
- You can confirm the docker containers are working correctly with the following command:
- Now navigate to :81 in a web browser, the default login is firstname.lastname@example.org and changeme. You will need to change this username and password before proceeding.
- Once you've changed the username and password for your Ngnix Proxy Manager you will be able to access the dashboard, here you will want to navigate to Hosts > Proxy Hosts
- In proxy hosts click the Add Proxy button, this will take you to the below window where you will enter your Domain Name, and fill out scheme, forward hostname and forward port.
- At this point if you are using a self signed certificate continue on this guide.
- Move to the SSL tab of this window and enter the below information, make sure to add a valid email address incase you need to recover this certificate.
- click save, this will then create the proxy host pointing at the Nextcloud container with a valid certificate.
- You can now force the use of https by clicking edit on the proxy host, navigating to the SSL tab and ticking Force SSL, HTTP/2 Support, and HSTS Enabled on
- Verification of this process can be done by navigating to your domain/subdomain and accessing Nextcloud.
- If the SSL Certificate fails ensure that your firewall is not blocking port 80 (required to contact Lets Encrypt)
- If you are unable to access your nextcloud ensure that your ports are forwarded correctly, and that you've created a valid A record, keep in mind some DNS providers can take up to 48 hours to update
- If you are receiving network errors after removing an interface or IP from your host machine running the below commands will generally resolve the problem:
iptables -t filter -N DOCKER
systemctl restart docker.services
- Once docker is restarted pulling your container down and back up will resolve the networking error.
- If you are having a bad gateway error on your nginx after setup it may be caused by the docker container not creating the necessary config.json file. If this is the case simply create a config.json file in the /opt/nextcloud folder and enter the below text