文章首发于:Panda's Blog
上两篇文章中配置好了HTTPS,此篇中将配置集成OnlyOffic实现在线编辑和预览office文档。
通过Docker运行OnlyOffic
下载安装Docker并启动服务
注:此处选用的是阿里云镜像
[root@ecs-a869 ~]# cd /etc/yum.repos.d/
[root@ecs-a869 yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@ecs-a869 yum.repos.d]# yum -y install docker-ce
[root@ecs-a869 yum.repos.d]# systemctl start docker
下拉OnlyOffic文件至服务器
[root@ecs-a869 yum.repos.d]# docker pull onlyoffice/documentserver
上传SSL证书
打开宝塔下载证书
解压下载的压缩包
将Nginx文件夹下的.key文件和.pem文件改名为onlyoffice.key和onlyoffice.crt
新建证书目录
[root@ecs-a869 yum.repos.d]# mkdir -pv /app/onlyoffice/DocumentServer/data/certs
mkdir: created directory '/app'
mkdir: created directory '/app/onlyoffice'
mkdir: created directory '/app/onlyoffice/DocumentServer'
mkdir: created directory ‘/app/onlyoffice/DocumentServer/data'
mkdir: created directory ‘/app/onlyoffice/DocumentServer/data/certs'
打开宝塔面板,将key和crt上传至/app/onlyoffice/DocumentServer/data/certs
目录下
检查是否上传
[root@ecs-a869 yum.repos.d]# cd /app/onlyoffice/DocumentServer/data/certs
[root@ecs-a869 certs]# ls
onlyoffice.crt onlyoffice.key
运行OnlyOffic镜像
[root@ecs-a869 certs]# docker run -i -t -d --restart=always -p 643:443 -v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data onlyoffice/documentserver
a5d3e840adcd1a37ab6c152fcbb2bf2013bc5eef6430037ef67e67327d8fe411
查看是否运行
[root@ecs-a869 certs]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5d3e840adcd onlyoffice/documentserver "/bin/sh -c /app/onl…" 49 seconds ago Up 47 seconds 80/tcp, 0.0.0.0:643->443/tcp upbeat_lamarr
宝塔面板放行643端口
测试
浏览器访问https://IP或域名:643/welcome
添加onlyoffice支持
[root@ecs-a869 certs]# vi /home/seafile/conf/seahub_settings.py
# -*- coding: utf-8 -*-
SECRET_KEY = "d)q15=cdy!gge=v23%s@s2$pc)*vayoi3y+6vkip6310u$nvnj"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'seahub-db',
'USER': 'seafile',
'PASSWORD': '******',
'HOST': '127.0.0.1',
'PORT': '3306'
}
}
~
~
~
~
~
~
~
"/home/seafile/conf/seahub_settings.py" 14L, 315C
i 键 或 INSERT 键 修改
修改完成后 Esc 键 退出修改
:wq
保存退出
添加以下内容
# Enable Only Office
ENABLE_ONLYOFFICE = True
VERIFY_ONLYOFFICE_CERTIFICATE = True
ONLYOFFICE_APIJS_URL = 'https://域名或IP地址:643/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','doc','xls','ppt')
在宝塔面板网站配置文件头部中添加以下内容
# 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;
}
在searver配置段下添加以下内容
location /onlyofficeds/ {
proxy_pass http://127.0.0.1:643/;
proxy_http_version 1.1;
client_max_body_size 100M; # Limit Document size to 100MB
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;
}
注意添加位置
修改SERVICE_URL
[root@ecs-a869 certs]# vi /home/seafile/conf/ccnet.conf
[General]
USER_NAME = seafile
ID = e8ca5e17f6df037a25217b5086920a824703801a
NAME = seafile
SERVICE_URL = http://cloud.****.com.cn:8000
[Client]
PORT = 13419
[Database]
ENGINE = mysql
HOST = 127.0.0.1
PORT = 3306
USER = seafile
PASSWD = abc123
DB = ccnet-db
CONNECTION_CHARSET = utf8
~
~
~
~
~
"/home/seafile/conf/ccnet.conf" 18L, 287C
将SERVICE_URL = http://cloud.****.com.cn:8000
修改为SERVICE_URL = https://cloud.****.com.cn:8888
根据自己使用的域名及端口号修改
重启
[root@ecs-a869 certs]# cd /home/seafile/seafile-server*
[root@ecs-a869 seafile-server-7.0.4]# ./seafile.sh restart
Stopping seafile server ...
[07/27/19 22:49:58] ../common/session.c(132): using config file /home/seafile/conf/ccnet.conf
Starting seafile server, please wait ...
** Message: seafile-controller.c(718): No seafevents.
Seafile server started
Done.
[root@ecs-a869 seafile-server-7.0.4]# ./seahub.sh restart
Stopping seahub ...
LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...
Seahub is started
Done.
[root@ecs-a869 seafile-server-7.0.4]# service nginx restart
Stoping nginx... done
Starting nginx... done