如何在 Debian 11 上使用 Nginx 和 SSL 安装 Etherpad
在此页
- 先决条件
- 安装依赖包
- 安装和配置 MariaDB 数据库
- 安装和配置 Etherpad
- 安装和配置 Nginx
- 验证 Etherpad 安装
- 结论
Etherpad 是 Google Docs 和 Zoho Writer 等服务的免费开源替代品。 Etherpad 是适合您团队的协作式实时文本编辑器,由于 Etherpad 是基于 Web 的文本编辑器,因此可以随时随地访问。
Etherpad 上的任何更改都是实时发生的,并且 etherpad 还支持团队的版本控制和内置格式。 Etherpad 是一个高度可定制的编辑器,支持各种插件。并且还支持doc、pdf、odt、markdown等现代文档格式。
在本教程中,您将在 Debian 11 Bullseye 上安装和配置 Etherpad 实时协作编辑器。本教程使用 MariaDB 作为数据库后端,使用 Nginx Web 服务器作为启用安全 HTTPS 的反向代理。最后,您将安装 Etherpad 并通过安全的 HTTPS 加密进行保护。
先决条件
为了完成本教程,您首先需要满足以下要求:
- 一台 Debian 11 服务器,您可以使用 1 GB 的 RAM 进行测试。对于生产,您可以使用更多资源,具体取决于您的环境和使用情况。
- 具有 root 权限的非 root 用户。或者,您可以使用 root 用户。
- 用于安装的域名,并确保它指向服务器 IP 地址。在此示例中,我们将使用域 etherpad.example.io。
满足所有这些先决条件后,请继续执行第一部分以开始安装。
安装包依赖
Etherpad 是一个构建在 Node.js 之上的 Web 应用程序。在撰写本文时,Etherpad 的最新版本是 xxx,并且至少需要 Node.js 版本 14.x。在本节中,您将安装一些包依赖项,包括 Node.js 到 Debian 11 服务器。
1. 首先,刷新您的包索引列表,然后通过运行以下命令安装构建依赖项。
sudo apt update
sudo apt install gzip git curl python libssl-dev pkg-config gcc g++ make build-essential -y
2. 在本教程中,您将从 Nodesource 存储库安装 Node.js,该存储库提供多个版本的 Node.js。本教程使用 Node.js 版本 16.x 进行 Etherpad 安装。
现在,执行以下命令将 Node.js 存储库添加到您的系统。此命令将自动添加 Nodesource 存储库以刷新您的包索引。
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
3. 接下来,通过运行以下命令从 Nodesource 存储库安装 Node.js 16.x。
sudo apt install nodejs -y
4. 安装完成后,使用以下命令验证您的 Node.js 版本。
node --version
你会收到类似 blah blah 的输出。
在本节中,您已经从 Nodesource 存储库安装了 Etherpad 和 Node.js 版本 16.x 的包依赖项。接下来,您将安装和配置 MariaDB 数据库。
安装和配置 MariaDB 数据库
在本节中,您将在 Debian 11 服务器上安装 MariaDB 数据库。然后,您将为 MariaDB 设置根密码,最后,您将为 Etherpad 创建一个新的数据库和用户。
1. 默认情况下,MariaDB 软件包在 Debian 11 存储库中可用。运行以下命令来安装它。
sudo apt install mariadb-server -y
2. MariaDB 安装完成后,会自动运行并启用。
MariaDB 提供了一个命令行工具,可以帮助您安全地部署 MariaDB,包括为 MariaDB 设置 root 密码。执行命令 mysql_secure_installation 如下。
mysql_secure_installation
现在系统会询问您一些与 MariaDB 部署相关的问题,并提示您设置 root 密码。
3. mariaDB默认root用户没有密码,按回车。
Enter current password for root (enter for none):
OK, successfully used password, moving on...
4. 现在系统会要求您使用 unix_socket 切换身份验证方法,键入 Y 表示同意。
Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
... Success!
5. 键入 Y 为 MariaDB 设置新的 root 密码。然后输入您的强密码并重复。
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
6. 默认的 MariaDB 安装带有一个匿名用户。键入 Y 将其删除。
Remove anonymous users? [Y/n] Y
... Success!
7. 现在,禁用 MariaDB root 用户的远程登录。输入 Y 表示同意。
Disallow root login remotely? [Y/n] Y
... Success!
8. 接下来,键入 Y 同意并删除默认数据库测试及其之上的所有权限。
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
9. 最后,重新加载表权限以应用新配置。输入 Y 表示同意并按 ENTER。
Reload privilege tables now? [Y/n] Y
... Success!
完成所有配置后,您将收到诸如 All done! 之类的输出消息。如下。
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
10.接下来,运行以下命令登录MariaDB shell。系统将提示您输入 MariaDB root 密码。输入您的密码。
mysql -u root -p
11. 现在,通过运行以下查询为 Etherpad 创建一个新的数据库和用户。此示例将使用用户 etherpaduser 和密码 StrongPasswordEtherpadDB 创建一个新数据库 etherpad_lite_db。请务必更改密码。
CREATE DATABASE etherpad_lite_db;
CREATE USER [email ;
12. 之后,重新加载所有表权限以应用新配置,然后运行退出查询以从 mariaDB shell 注销。
FLUSH PRIVILEGES;
EXIT

在本节中,您已经在 Debian 11 上完成了 MariaDB 数据库的安装和配置。此外,您还为 Etherpad 创建了数据库和用户。接下来,您将下载 Etherpad 源代码并安装它。
安装和配置 Etherpad
在本节中,您将从源代码安装 Etherpad,然后使用 MariaDB 作为数据库对其进行配置,并为 Etherpad 创建一个新的 systemd 文件。最后,Etherpad 将作为 systemd 服务运行。
1. 在下载 Etherpad 源代码之前,您需要在您的系统上创建一个新用户 etherpad。该用户将用于运行 Etherpad 安装程序脚本并运行 Etherpad 服务。
执行下面的 adduser 命令来创建一个新用户 etherpad。此外,将主目录定义为 /opt/etherpad-lite。该目录将用于存储所有 Etherpad 源。
sudo adduser --system --no-create-home --home=/opt/etherpad-lite --group etherpad
2. 现在,导航到目录 /opt 并使用 git 命令克隆 Etherpad 源。
cd /opt/
git clone --branch master https://github.com/ether/etherpad-lite.git
3. 之后,将 etherpad-lite 目录的所有权更改为用户 etherpad 和组 etherpad。
sudo chown -R etherpad:etherpad etherpad-lite
4. 现在导航到目录 etherpad-lite/ 并使用安装程序脚本 installDeps.sh 安装所有 Node.js 依赖项,如下所示。安装程序脚本 installDeps.sh 将作为非根用户 etherpad 运行。
cd /opt/etherpad-lite
sudo su -s /bin/bash -c "./bin/installDeps.sh" etherpad
等待所有包依赖安装完成。
接下来,修改文件 settings.json 以设置 Etherpad 安装。您可以使用 nano 编辑器来编辑该文件或使用您喜欢的编辑器。
nano settings.json
在该行的顶部,将标题更改为您自己的标题。此示例使用标题 Entherpad Johndoe。
"title": "Etherpad Johndoe",
在本教程中,Etherpad 将在 Nginx 反向代理下运行。在本地主机上运行 Etherpad 对安全性有好处。现在,将 ip: 配置更改为 127.0.0.1。使用此配置,Etherpad 将仅在本地主机上运行。
"ip": "127.0.0.1",
"port": 9001,
默认情况下,Etherpad 使用 SQLite 作为数据库。注释所有这些行以禁用。
/*
*"dbType": "dirty",
*"dbSettings": {
* "filename": "var/dirty.db"
*},
*/
现在,在下面输入 MariaDB 数据库配置。并确保更改数据库名称、用户和密码。
"dbType" : "mysql",
"dbSettings" : {
"user": "etherpaduser",
"host": "localhost",
"port": 3306,
"password": "StrongPasswordEtherpadDB",
"database": "etherpad_lite_db",
"charset": "utf8mb4"
},
保存并退出文件。
接下来,在目录/etc/systemd/system 中创建一个新的systemd 服务文件etherpad.service。该文件将包含 Etherpad 在服务器上正常运行所需的所有配置详细信息。使用 nano 编辑器创建它。
sudo nano /etc/systemd/system/etherpad.service
将以下配置添加到文件中。
[Unit]
Description=Etherpad-lite, the collaborative editor.
After=syslog.target network.target
[Service]
Type=simple
User=etherpad
Group=etherpad
WorkingDirectory=/opt/etherpad-lite
Environment=NODE_ENV=production
ExecStart=/usr/bin/node --experimental-worker /opt/etherpad-lite/node_modules/ep_etherpad-lite/node/server.js
# use mysql plus a complete settings.json to avoid Service hold-off time over, scheduling restart.
Restart=always
[Install]
WantedBy=multi-user.target
该服务文件将作为用户和组 etherpad 运行。您会注意到选项 Environment=NODE_ENV=production,这意味着 Etherpad 应用程序将在生产环境中运行。 ExecStart=.. 选项是运行 Etherpad 应用程序的默认命令。
保存并关闭文件。
现在,重新加载 systemd 管理器以应用新的服务文件。
sudo systemctl daemon-reload
之后,启动并启用 etherpad 服务,然后通过运行以下命令验证其状态。
sudo systemctl enable --now etherpad
sudo systemctl status etherpad
您将收到类似于下面屏幕截图的输出。 etherpad 服务现在处于活动状态(正在运行),它将在系统启动时自动启动,并在默认端口 9001 的本地主机上运行。

至此,您已经完成了 Etherpad 的安装。接下来,您将安装 Nginx,将其设置为 Etherpad 应用程序的反向代理。
安装和配置 Nginx
对于生产环境,始终建议在您的应用程序前面放置一个反向代理。它将提高您的应用程序性能和安全性。在本节中,您将安装 Nginx Web 服务器并将其配置为反向代理。最后,您将使用您的域名运行 Etherpad,并使用 HTTPS 协议进行保护。
1. 首先,通过运行以下命令安装 Nginx 包。
sudo apt install nginx -y
2. 现在,如果您的 Debian 系统上安装了 UFW 防火墙。通过运行下面的 ufw 命令允许公共访问 HTTP 和 HTTPS 端口(80 和 443)。
sudo ufw allow "Nginx Full"
您将收到以下输出。
Rule added
Rule added (v6)
3. 接下来,在目录/etc/nginx/sites-available/ 中创建一个新的Nginx 虚拟主机文件etherpad。使用 nano 编辑器或您喜欢的编辑器创建它。
sudo nano /etc/nginx/sites-available/etherpad
将以下配置复制并粘贴到文件中。另外,将您的域名和 SSL 证书路径替换为您自己的信息。对于 SSL 证书,您可以使用 Letsencrypt 自由生成 SSL 证书。
# enforce HTTPS
server {
listen 80;
listen [::]:80;
server_name etherpad.example.io;
return 301 https://$host$request_uri;
}
# we're in the http context here
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name etherpad.example.io;
access_log /var/log/nginx/eplite.access.log;
error_log /var/log/nginx/eplite.error.log;
ssl_certificate /etc/letsencrypt/live/etherpad.example.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/etherpad.example.io/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 \
EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 \
EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
location / {
proxy_pass http://127.0.0.1:9001;
proxy_buffering off; # be careful, this line doesn't override any proxy_buffering on set in a conf.d/file.conf
proxy_set_header Host $host;
proxy_pass_header Server;
# Note you might want to pass these headers etc too.
proxy_set_header X-Real-IP $remote_addr; # https://nginx.org/en/docs/http/ngx_http_proxy_module.html
proxy_set_header X-Forwarded-For $remote_addr; # EP logs to show the actual remote IP
proxy_set_header X-Forwarded-Proto $scheme; # for EP to set secure cookie flag when https is used
proxy_http_version 1.1; # recommended with keepalive connections
# WebSocket proxying - from https://nginx.org/en/docs/http/websocket.html
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
此 Nginx 虚拟主机文件将自动将任何流量从 HTTP 重定向到安全的 HTTPS 协议。为了在出现错误时进行调试,请检查日志文件 /var/log/nginx/eplite.error.log。所有客户端请求都将发送到后端 proxy_pass 在本地主机端口 9001 上运行的 Etherpad 应用程序。
4. 保存并关闭文件,然后通过创建文件 etherpad 到目录 /etc/nginx/sites-enabled 的符号链接来激活虚拟主机配置。
sudo ln -s /etc/nginx/sites-available/etherpad /etc/nginx/sites-enabled/
5. 接下来,运行命令nginx -t 来验证nginx 配置。此命令将检查配置中的任何语法错误。
sudo nginx -t
您将收到如下输出。输出消息语法正常意味着您没有任何错误。
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful.
6. 最后,重启Nginx服务,应用一个新的Nginx虚拟主机文件。
sudo systemctl restart nginx
在本节中,您已完成 Nginx 安装和配置,作为 Etherpad 应用程序的反向代理。您的 Etherpad 现在可以在 http://etherpad.example.io 上使用。

验证 Etherpad 安装
1. 打开您的网络浏览器并在地址中输入域名 http://etherpad.example.io/。您将自动重定向到安全的 HTTPS 连接,如下所示。

2. 要创建一个新焊盘,在列中输入焊盘的名称,然后单击“确定”按钮。
现在您将看到如下所示的 Etherpad 实时协作编辑器。

结论
在本教程中,您已经在 Debian 11 服务器上安装并配置了 Etherpad 实时协作编辑器。此外,您还安装并配置了 Nginx 作为 Etherpad 应用程序的反向代理。
您现在已准备好使用 etherpad 作为您团队中的协作编辑器。有关 Etherpad 的更多信息,请查看官方 Etherpad 文档。