This guide will help you get NextCloud up and running with Docker and CloudFlare Tunnels.

Prerequisites

  1. A running Docker environment.
  2. A Cloudflare account and Cloudflare Tunnel setup.
  3. Basic Portainer knowledge.
  4. Basic knowledge of Docker Compose.

Step 1: NextCloud Docker Compose

Create a docker-compose.yml file for your NextCloud instance:

version: '3.7'

services:
  nextcloud:
    image: nextcloud
    container_name: nextcloud
    ports:
      - 8080:80
    volumes:
      - nextcloud_data:/var/www/html
    environment:
      - MYSQL_PASSWORD=yourpassword
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db

  db:
    image: mariadb
    container_name: nextcloud_db
    environment:
      - MYSQL_ROOT_PASSWORD=yourpassword
      - MYSQL_PASSWORD=yourpassword
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    volumes:
      - db_data:/var/lib/mysql

volumes:
  nextcloud_data:
  db_data:

Run the Docker Compose file:

docker-compose up -d

Step 2: Setup your CloudFlare Tunnel and Zero-Trust

Please refer to this step-by-step post I made on how to setup your Cloudflare tunnel.
By doing this you will be able to give your Nextcloud instance a subdomain with an SSL certification.

Step 3: Edit NextCloud Container Files

  1. Log into Portainer.
  2. Find the NextCloud container and click the >_ icon to open the terminal.
  3. Click the blue Connect button.

If you do not have Portainer try installing the CLI application “ctop” to get into the Nextcloud exec shell. This should work in most Linux distro cli.

docker run --rm -ti \
--name=ctop \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
quay.io/vektorlab/ctop:latest

In the exec shell terminal window, enter the following:

apt update
apt install nano
nano .htaccess

Add the following to the top of the .htaccess file:

php_value upload_max_filesize 16G
php_value post_max_size 16G
php_value max_input_time 3600
php_value max_execution_time 3600
php_value memory_limit 2048M

Save and exit with CTRL+O and then CTRL+X.

Step 4: Remove Standard Error Codes in Nextcloud Overview

Nextcloud often shows warnings in the Overview section. Below are common warnings and how to resolve them:

Warning: “The reverse proxy header configuration is incorrect”

Add the following to your Nextcloud configuration file (config/config.php):

nano config/config.php

Scroll down to the 'trusted_domains' section and update it to include your domain:

'trusted_domains' => 
array (
  0 => '192.168.x.xxx:8080',
  1 => 'nextcloud.yourdomain.com',
),

Then scroll down to the bottom of the file where you should see:

'installed' => true,

Add the following before the last ");":

'overwriteprotocol' => 'https',
'default_phone_region' => 'US',
'enable_previews' => true,

Save and exit with CTRL+O and then CTRL+X.

Now, edit the 000-default.conf file:

nano /etc/apache2/sites-enabled/000-default.conf

Scroll to the end of the file and add the following:

Redirect 301 /.well-known/carddav https://nextcloud.yourdomain.com/remote.php/dav
Redirect 301 /.well-known/caldav https://nextcloud.yourdomain.com/remote.php/dav
Redirect 301 /.well-known/webdav https://nextcloud.yourdomain.com/remote.php/dav
Redirect 301 /.well-known/webfinger https://nextcloud.yourdomain.com/index.php
Redirect 301 /.well-known/nodeinfo https://nextcloud.yourdomain.com/index.php

Make sure to replace nextcloud.yourdomain.com with your actual NextCloud URL.

Step 5: Restart the NextCloud Docker Container

After making these changes, restart your NextCloud Docker container:

docker restart nextcloud

 

Conclusion

By following these steps, you should have successfully integrated NextCloud with Docker, Portainer, and Cloudflare Tunnels, along with configuring necessary settings and resolving common issues. This setup ensures your NextCloud instance is running efficiently and securely.

Feel free to reach out if you need further assistance or clarifications!