> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/di-36-zhang-web-fu-wu-qi/di-36.8-jie-onlyoffice-bu-shu-ji-yu-postgresql.md).

# 36.8 OnlyOffice 部署（基于 PostgreSQL）

本节说明在 FreeBSD 上通过 pkg 部署 OnlyOffice，并与 Nginx + Nextcloud 协同工作的完整步骤。

```sh
用户浏览器
   │
   ▼
Nextcloud + Nginx（机器 A，文件管理）
   │
   │ 调用文档编辑接口
   ▼
OnlyOffice Document Server（机器 B）
   ├── Nginx（反向代理）
   ├── PostgreSQL（数据存储）
   └── RabbitMQ（消息队列）
```

## 安装 Nextcloud 和 Nginx

OnlyOffice 需与 Nextcloud 配合使用，首先在另一台机器上安装 Nextcloud 和 Nginx。安装完成后，才能开始部署 OnlyOffice 文档服务器。

## 安装 OnlyOffice

使用 pkg 包管理器安装 OnlyOffice 是最简便的方式，执行以下命令完成安装：

```sh
# pkg install onlyoffice-documentserver
```

或者使用 Ports 方式安装 OnlyOffice：

```sh
# cd /usr/ports/www/onlyoffice-documentserver/
# make install clean
```

## 查看 OnlyOffice 安装信息

目录结构：

```sh
/
├── usr
│   └── local
│       ├── etc
│       │   ├── onlyoffice
│       │   │   └── documentserver
│       │   │       ├── local.json                      # OnlyOffice 本地配置文件
│       │   │       ├── default.json                    # OnlyOffice 默认配置文件
│       │   │       ├── nginx
│       │   │       │   └── ds.conf                     # OnlyOffice Nginx 配置
│       │   │       └── supervisor
│       │   │           └── *.conf                      # OnlyOffice supervisord 配置
│       │   └── supervisord.conf                        # supervisord 主配置文件
│       ├── bin
│       │   ├── documentserver-pluginsmanager.sh       # 插件管理器脚本
│       │   └── documentserver-update-securelink.sh    # 安全链接更新脚本
│       └── www
│           └── onlyoffice
│               └── documentserver
│                   └── server
│                       └── schema
│                           ├── postgresql
│                           │   ├── createdb.sql      # PostgreSQL 数据库创建脚本
│                           │   └── upgrade           # PostgreSQL 升级脚本
│                           └── mysql
│                               ├── createdb.sql      # MySQL 数据库创建脚本
│                               └── upgrade           # MySQL 升级脚本
└── var
    ├── log
    │   └── onlyoffice
    │       └── documentserver
    │           └── converter
    │               └── out.log                        # OnlyOffice 日志文件
    └── db
        └── rabbitmq
            └── .erlang.cookie                          # RabbitMQ Erlang Cookie
```

安装完成后，查看安装包的说明文档，了解必要的配置和注意事项：

```sh
# pkg info -D onlyoffice-documentserver
```

## 配置服务

了解安装信息后，需配置 OnlyOffice 相关服务的开机自启。

```sh
# service nginx enable
# service rabbitmq enable
# service supervisord enable
```

## 配置数据库

OnlyOffice 需要数据库存储数据，本节使用 PostgreSQL 作为数据库。请自行参照本书其他章节，完成 PostgreSQL 数据库的安装、初始化和服务自启。

随后执行以下命令使用数据库：

```sh
# psql -U postgres -c "CREATE DATABASE onlyoffice;"
# psql -U postgres -c "CREATE USER onlyoffice WITH password 'onlyoffice';"
# psql -U postgres -c "GRANT ALL privileges ON DATABASE onlyoffice TO onlyoffice;"
# psql -U postgres -c "ALTER DATABASE onlyoffice OWNER to onlyoffice;"
# psql -hlocalhost -Uonlyoffice -d onlyoffice -f /usr/local/www/onlyoffice/documentserver/server/schema/postgresql/createdb.sql
```

## 配置 rabbitmq

OnlyOffice 需使用 RabbitMQ 作为消息队列服务。启动服务：

```sh
# service rabbitmq start
```

第一步：

```sh
# rabbitmqctl --erlang-cookie `cat /var/db/rabbitmq/.erlang.cookie` add_user onlyoffice password  # 注意：该步骤可能耗时数分钟，下同

……此处省略部分内容……

attempted to contact: [rabbit@ykla]

rabbit@ykla:
  * connected to epmd (port 4369) on ykla
  * epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic
  * can't establish TCP connection to the target node, reason: timeout (timed out)
  * suggestion: check if host 'ykla' resolves, is reachable and ports 25672, 4369 are not blocked by firewall

Current node details:
 * node name: 'rabbitmqcli-719-rabbit@ykla'
 * effective user's home directory: /root
 * Erlang cookie hash: mmhdcv/DKEfjrCrCEaZMvQ==
```

第二步：

```sh
# rabbitmqctl --erlang-cookie `cat /var/db/rabbitmq/.erlang.cookie` set_user_tags onlyoffice administrator
Error: unable to perform an operation on node 'rabbit@ykla'. Please see diagnostics information and suggestions below.

……此处省略部分内容……

```

第三步：

```sh
# rabbitmqctl --erlang-cookie `cat /var/db/rabbitmq/.erlang.cookie` set_permissions -p / onlyoffice ".*" ".*" ".*"
Error: unable to perform an operation on node 'rabbit@ykla'. Please see diagnostics information and suggestions below.

……此处省略部分内容……

```

## 允许局域网访问

OnlyOffice 默认配置不允许私有 IP 地址访问，需修改配置以允许局域网访问。将以下片段加入 **/usr/local/etc/onlyoffice/documentserver/local.json** 文件：

```json
  "request-filtering-agent" : {
				"allowPrivateIPAddress": true,
				"allowMetaIPAddress": true
			},
```

即：

```json
{
  "services": {
    "CoAuthoring": {
      "sql": {
        "type": "postgres",
        "dbHost": "localhost",
        "dbPort": "5432",
        "dbName": "onlyoffice",
        "dbUser": "onlyoffice",
        "dbPass": "onlyoffice"
      },
  "request-filtering-agent" : {
				"allowPrivateIPAddress": true,
				"allowMetaIPAddress": true
			},
      "token": {
        "enable": {
          "request": {
            "inbox": false,
            "outbox": false
          },
          "browser": false

//……此处省略其他配置……

```

## 配置 Nginx

需配置 Nginx 提供 OnlyOffice 的 Web 访问服务。编辑 **/usr/local/etc/nginx/nginx.conf** 文件，将

```nginx
include /usr/local/etc/onlyoffice/documentserver/nginx/ds.conf;
```

添加至 `http` 配置块内：

示例：

```nginx

# ……省略其他配置……

http {
    include       mime.types;
    default_type  application/octet-stream;
    include /usr/local/etc/onlyoffice/documentserver/nginx/ds.conf;

# ……省略其他配置……

```

## 配置 supervisord

OnlyOffice 使用 supervisord 来管理其服务进程。编辑 **/usr/local/etc/supervisord.conf** 文件，找到末尾的 `;[include]`，删除行首的分号：

即：

```ini
[include]
;files = relative/directory/*.ini
files = /usr/local/etc/onlyoffice/documentserver/supervisor/*.conf
```

```sh
# service supervisord start
```

## 启动服务

所有配置完成后，可启动 OnlyOffice 文档服务。

```sh
# documentserver-update-securelink.sh
ds:docservice: stopped
ds:docservice: started
ds:converter: stopped
ds:converter: started
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
```

直接访问 IP 地址，如下图所示：

![Document Server is running](/files/fX16wv47obUiD4lAa4hk)

## 配置 Nextcloud

OnlyOffice 文档服务启动后，需在 Nextcloud 中配置 OnlyOffice 插件。打开 Nextcloud：

安装 OnlyOffice 插件，可访问 `ip/nextcloud/index.php/settings/apps/office/onlyoffice`：

![onlyoffice](/files/M1b5GQfW5UNsrLrGA653)

点击头像，随后进入管理设置，找到 OnlyOffice，设置如下（注意确认密钥是否为空）：

![onlyoffice](/files/p2ZLmyxufyGvM878aWex)

## 完成

所有配置完成后，可测试 OnlyOffice 功能，预览几个文件：

![onlyoffice](/files/DqEihxkDMb0v5rrcYh22)

![onlyoffice](/files/YPhOK8gADCTYhZ9SAzls)

![onlyoffice](/files/tDnuiTRKtC2wt6s4cfnw)

## 故障排除与未竟事宜

如在使用 OnlyOffice 时遇到问题，可查看相关日志文件排查。本节还列出了有待完善的事项。

OnlyOffice 的日志位于 **/var/log/onlyoffice/documentserver/converter/out.log**。

## 参考文献

* Ascensio System SIA. How to allow Private IP to access onlyOffice documentServer?\[EB/OL]. \[2026-03-25]. <https://forum.onlyoffice.com/t/how-to-allow-private-ip-to-access-onlyoffice-documentserver/5755/2>. 提供了私有 IP 地址访问 OnlyOffice 的配置方法。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-36-zhang-web-fu-wu-qi/di-36.8-jie-onlyoffice-bu-shu-ji-yu-postgresql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
