Onlyoffice Documentserver

From ArchWiki

Onlyoffice Documentserver is a full-featured backend for editing different office documents like Open Document, Word, Excel, etc. online in your browser. The software is open source and can be easily deployed and integrated into existing server software. Available frontends are Nextcloud or the Onlyoffice CommunityServer. It can be also used in own software, see following examples for PHP, Nodejs, etc.

Installation

Install the onlyoffice-documentserver-binAUR package. Further you will need PostgreSQL as a database backend and the Redis and rabbitmq services installed.

Alternatively, install via docker and run:

$ docker pull onlyoffice/documentserver
$ docker run -i -t -d -p PORT:80 --restart=always onlyoffice/documentserver

Where PORT can be either 80, if not already in use by another web server, or different, e.g. 9980.

Configuration

Database

The PostgreSQL database backend needs to be configured. Here is an example database setup:

$ sudo -i -u postgres psql -c "CREATE DATABASE onlyoffice;"
$ sudo -i -u postgres psql -c "CREATE USER onlyoffice WITH password 'onlyoffice';"
$ sudo -i -u postgres psql -c "GRANT ALL privileges ON DATABASE onlyoffice TO onlyoffice;"

To migrate the documentserver database schema, run following command:

$ psql -hlocalhost -Uonlyoffice -d onlyoffice -f /usr/share/webapps/onlyoffice/documentserver/server/schema/postgresql/createdb.sql

Webserver

Nginx / no SSL

Here is an example for the Nginx webserver:

/etc/nginx/sites-available/onlyoffice-documentserver
map $http_host $this_host {
  "" $host;
  default $http_host;
}
map $http_x_forwarded_proto $the_scheme {
  default $http_x_forwarded_proto;
  "" $scheme;
}
map $http_x_forwarded_host $the_host {
  default $http_x_forwarded_host;
  "" $this_host;
}
map $http_upgrade $proxy_connection {
  default upgrade;
  "" close;
}
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $the_host;
proxy_set_header X-Forwarded-Proto $the_scheme;
server {
  listen 0.0.0.0:80;
  listen [::]:80 default_server;
  server_tokens off;
  rewrite ^\/OfficeWeb(\/apps\/.*)$ /web-apps$1 redirect;
  location / {
    proxy_pass http://localhost:8000;
    proxy_buffers 4 256k; 
    proxy_max_temp_file_size 0;
  }
  location /spellchecker/ {
    proxy_pass http://localhost:8080/;
  }
}

Nginx / reverse proxy with SSL

Create a Nginx configuration file like the following:

/etc/nginx/conf.d/onlyoffice.conf
upstream docservice {
  server 127.0.0.1:PORT;
}

map $http_host $this_host {
    "" $host;
    default $http_host;
}

map $http_x_forwarded_proto $the_scheme {
     default $http_x_forwarded_proto;
     "" $scheme;
}

map $http_x_forwarded_host $the_host {
    default $http_x_forwarded_host;
    "" $this_host;
}

map $http_upgrade $proxy_connection {
  default upgrade;
  "" close;
}

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $the_host;
proxy_set_header X-Forwarded-Proto $the_scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

server {
    listen 0.0.0.0:443 ssl;
    listen [::]:443 ssl default_server;
    server_name SERVER_NAME
    server_tokens off;
    root /usr/share/nginx/html;

    ssl_certificate SSL_CERT;
    ssl_certificate_key SSL_KEY;
    ssl_verify_client off;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_prefer_server_ciphers   on;

    add_header X-Content-Type-Options nosniff;
    location / {
      proxy_pass http://docservice;
      proxy_http_version 1.1;
  }
}

Fill in PORT, SERVER_NAME, SSL_CERT and SSL_KEY. This was taken from the nginx reference config.

Reload Nginx:

$ nginx -t
$ nginx -s reload

Starting

Enable and start the following services if you wish to use them locally on the same machine:

  • rabbitmq
  • redis
  • postgresql

Finally, start the documentserver services:

  • onlyoffice-spellchecker
  • onlyoffice-fileconverter
  • onlyoffice-docservice

Nextcloud app

Install the ONLYOFFICE app within Nextcloud. Enter Nextcloud / Settings / ONLYOFFICE and fill in Onlyoffice Docs address with https://SERVER_NAME.

Troubleshooting

Onlyoffice Docker Container on ZFS

When running onlyoffice/documentserver as a Docker container with the data-root pointing to a ZFS device, e.g. when /var is mounted as a ZFS pool, docker run might fail with Error: Daemon failed to copy files.

In this case, let Docker have its data-root on an ext4 partition, for instance /var_ext4/lib/docker:

/etc/docker/daemon.json
{
    "data-root": "/var_ext4/lib/docker"
}