Setting Up Nextcloud 13 and Collabora Online for Private Online Office Platform with Docker

· 3 min read
Setting Up Nextcloud 13 and Collabora Online for Private Online Office Platform with Docker

Nextcloud is a popular open-source online file storage solution, and Collabora Online, a LibreOffice-based online office suite, adds more along with NextCloud. The combination of the two is a powerful self-hosting alternative to Google Drive and Google Docs. And they could be easily set up using Docker and Nginx (or any other reverse proxy you like).

Collabora Online supports dozens of document formats including DOC, DOCX, PPT, PPTX, XLS, XLSX + ODF, Import/View Visio, Publisher and many more...[1]

Setting Up Docker Services

Nextcloud could work with SQLite, MariaDB or Postgresql, and optional redis cache support. Here we would run Nextcloud with MariaDB and redis. Using the docker-compose.yml file:

version: '2'
services:
    'nc':
        image: 'nextcloud:latest'
        ports:
            - '127.0.0.1:8180:80'
            - '127.0.0.1:9980:9980'
        volumes:
            - '/srv/nextcloud/drive:/var/www/html'
        links:
            - 'redis:redis'
        depends_on:
            - 'redis'
        restart: always
    'redis':
        image: 'redis:latest'
        restart: always
    'db':
        image: 'mariadb:latest'
        volumes:
            - '/mnt/docker/data/nextcloud-db:/var/lib/mysql'
        environment:
            - 'MYSQL_ROOT_PASSWORD=${password}'
        restart: 'unless-stopped'
    'code-office':
        image: 'collabora/code:latest'
        environment:
            - "domain=${your_nextcloud_domain1}[|${your_nextcloud_domain2}]"
            - 'username=${admin}'
            - 'password=${password}'
        cap_add:
            - 'MKNOD'
        network_mode: 'service:nc' # !important
        restart: 'unless-stopped'

Here we are using a trick: adding CODE[2] container to Nextcloud container network by network_mode: 'service:nc'. This enables full access between NextCloud and Collabora Online, and makes life easier. When you get prepared, just run the containers:

$ docker-compose up -d

Setting Up Reverse Proxy

Configure Nginx as a reverse proxy for Nextcloud:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name drive.sakuragawa.moe;

    ssl on;
    ssl_certificate /path/to/your/certficate;
    ssl_certificate_key /path/to/your/key;

    client_max_body_size 10G;

    location / {
        proxy_pass http://localhost:8180;
        proxy_redirect default;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
    }
}

Then add another server for Collabora Online:

server {
    listen 443 ssl http2;
    # You can set a dedicated domain like:
    server_name office.sakuragawa.moe;

    ssl on
    ssl_certificate /path/to/your/certficate;
    ssl_certificate_key /path/to/your/key;

    # Static files
        location ^~ /loleaflet {
        proxy_pass https://localhost:9980;
        proxy_set_header Host $http_host;
    }

    # WOPI discovery URL
    location ^~ /hosting/discovery {
        proxy_pass https://localhost:9980;
        proxy_set_header Host $http_host;
    }

    # Main websocket
    location ~ /lool/(.*)/ws$ {
        proxy_pass https://localhost:9980;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $http_host;
        proxy_read_timeout 36000s;
    }

    # Admin Console websocket
    location ^~ /lool/adminws {
        proxy_pass https://localhost:9980;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $http_host;
        proxy_read_timeout 36000s;
    }

    # Download, presentation and image upload
    location ^~ /lool {
        proxy_pass https://localhost:9980;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $http_host;
    }
}

Then test and reload nginx:

$ nginx -t
$ systemctl reload nginx

You should be able to access Nextcloud at nextcloud.sakuragawa.moe now. You absolutely need to replace it with your own domain and prepare your SSL certificates.

Configure Nextcloud

Log in Nextcloud as admin, then click you avatar at the top-right and go to Apps menu. In Office & text tab, find Collabora Online and click Enable.
Screenshot-2018-3-16-Apps---------
Then open Settings, find Collabora Online, fill in your CODE server, and then click Apply. Your private G Suite is now set and go.
Screenshot-2018-3-16-------


  1. https://nextcloud.com/collaboraonline/ ↩︎

  2. Collabora Online Developer Edition ↩︎