【seafile】配合 OnlyOffice 实现文档在线编辑

本文最后更新于:2022年11月4日 下午

整合 OnlyOffice 就可以在线打开各种办公文档进行编辑。

前言

首先 Seafile pro 版支持多种 Office 在线预览和编辑的方式。

预览编辑安装方式
office-preview✔️专业版7.1 ~ 8.0 版本自带,9.0 及以后版本对接镜像 office
Microsoft Office Online Server✔️✔️仅 Windows 服务器可部署
Collabora Online (LibreOffice Online)✔️✔️docker 部署必须启用 https
OnlyOffice【推荐】✔️✔️docker部署

教程

  1. Seafile 整合 OnlyOffice 官方文档
  2. 用 Docker 部署 Seafile 专业版
  3. 用 Docker 部署 OnlyOffice

准备工作

将 OnlyOffice 加入到

将以下内容添加到 docker-compose.ymlservices

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
services:
...
oods:
image: onlyoffice/documentserver:latest
container_name: seafile-oods
volumes:
- /opt/seafile/oods/DocumentServer/logs:/var/log/onlyoffice
- /opt/seafile/oods/DocumentServer/data:/var/www/onlyoffice/Data
- /opt/seafile/oods/DocumentServer/lib:/var/lib/onlyoffice
- /opt/seafile/oods/DocumentServer/local-production-linux.json:/etc/onlyoffice/documentserver/local-production-linux.json

networks:
- seafile-net
environment:
- JWT_ENABLED=true
- JWT_SECRET=your-secret-string

并且在 seafile 部分加入一行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
seafile:
image: docker.seadrive.org/seafileltd/seafile-pro-mc:latest
container_name: seafile
ports:
- "127.0.0.1:8000:80"
#- "127.0.0.1:8000:443" # If https is enabled, cancel the comment.
volumes:
- /opt/seafile/data:/shared # Requested, specifies the path to Seafile data persistent store.
environment:
...
depends_on:
- db
- memcached
- elasticsearch
# !加入下面这行!
- oods
networks:
- seafile-net

记得把 JWT_SECRET 改成一堆乱码并记住

初始化 OnlyOffice 配置文件

设置OnlyOffice自动保存

执行以下命令

1
2
mkdir -p /opt/seafile/oods/DocumentServer/
vim /opt/seafile/oods/DocumentServer/local-production-linux.json

并为 local-production-linux.json 添加内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"services": {
"CoAuthoring": {
"autoAssembly": {
"enable": true,
"interval": "5m"
}
}
},
"FileConverter": {
"converter": {
"downloadAttemptMaxCount": 1
}
}
}

将 OnlyOffice 加入到 nginx conf 中

修改容器的Nginx文件,而不是宿主机的文件!

1
vim /opt/seafile/data/nginx/conf/seafile.nginx.conf

seafile.nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Required for only office document server
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;
"" $host;
}
map $http_upgrade $proxy_connection {
default upgrade;
"" close;
}
server {
listen 80;
...

location /onlyofficeds/ {
proxy_pass http://oods/;
proxy_http_version 1.1;
client_max_body_size 100M;
proxy_read_timeout 3600s;
proxy_connect_timeout 3600s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $the_host/onlyofficeds;
proxy_set_header X-Forwarded-Proto $the_scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

修改 seahub_settings.py

seahub_settings.py

1
vim /opt/seafile/data/seafile/conf/seahub_settings.py

在最后面加入下面内容

1
2
3
4
5
6
7
8
# OnlyOffice
ENABLE_ONLYOFFICE = True
VERIFY_ONLYOFFICE_CERTIFICATE = True
ONLYOFFICE_APIJS_URL = 'https://你的seafile域名/onlyofficeds/web-apps/apps/api/documents/api.js'
ONLYOFFICE_FILE_EXTENSION = ('doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'odt',
'fodt', 'odp', 'fodp', 'ods', 'fods')
ONLYOFFICE_EDIT_FILE_EXTENSION = ('docx', 'pptx', 'xlsx')
ONLYOFFICE_JWT_SECRET = 'your-secret-string'

记得把 JWT_SECRET 改成之前的那堆乱码

重启 Seafile 容器

执行以下命令

1
2
docker-compose down
docker-compose up -d

等待几分钟让 OnlyOffice 容器完成初始化。然后便可以使用 OnlyOffice。


【seafile】配合 OnlyOffice 实现文档在线编辑
https://pawswrite.xyz/posts/d4c31257.html
作者
Rainbow
发布于
2022年10月13日
许可协议