Running Collabora Online with Nextcloud and nginx

Today Nextcloud announced support for online office with Collabora Online using a docker image to host the Collabora Online server.

The announcement contains steps of how to setup the docker image and integrate it with Nextcloud for users using apache as a web server, this post will explain how to set everything up with nginx.

Office Online

Starting the Collabora Online server

The "meat" of the online office setup is the Collabora Online server which takes care of the rendering and editing of the document. This server can be ran as an easy to use docker container which contains everything you need to run the server.

When starting the docker image we need to expose the port it listens to to the outside world and tell it the domain our Nextcloud server runs at.

docker run -t -d -p 9980:9980 -e "domain=example.com" --cap-add MKNOD collabora/code

Setup nginx as a reverse proxy

Since the docker container we use as a Collabora Online server doesn't come with valid certificates for your domain, we use nginx as a reverse proxy which will provide us with a valid ssl setup to connect our browser to.

You can either run this reverse proxy on a seperate (sub-)domain or add it to the same domain your Nextcloud runs on.

Add a new server block to your nginx config or add the location entries to an existing one if you're re-using the same domain.

server {
    listen       443 ssl;
    server_name  office.example.com;

    ssl_certificate /path/to/certficate;
    ssl_certificate_key /path/to/key;
    
    # static files
    location ^~ /loleaflet {
        proxy_pass https://localhost:9980;
        proxy_set_header Host $http_host;
    }

    # WOPI discovery URL
    location ^~ /hosting {
        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;
   }
   
   # download, presentation and image upload
   location ~ ^/lool {
       proxy_pass https://localhost:9980;
       proxy_set_header Host $http_host;
   }
   
   # 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;
   }
   
   # Capabilities
   location ^~ /hosting/capabilities {
       proxy_pass https://localhost:9980;
       proxy_set_header Host $http_host;
   }
}

And reload your nginx config using sudo nginx -s reload.

Install the Nextcloud app

  1. Go to the Apps section and choose "Office & Text"
  2. Install the "Collabora Online" app
  3. In Admin -> Collabora Online specific the server you have setup before (https://office.example.com)

Enjoy

Now you can open the "Collabora Online" app and edit all your documents right in your browser.