Firefox Send,一个简单、私密的文件分享服务,它有阅后即焚功能,非常适合临时文件分享。可惜的是,由于被滥用,Mozilla 于 2020 年 9 月 17 日宣布永久关闭 Firefox Send。但是它的源代码是公开的,目前有一个主要由 Timvisee 维护的社区版 https://github.com/timvisee/send,我们要安装的就是这个版本。

整个流程主要参照 ditatompel Insights 的教程: Install self-hosted community-driven Firefox Send (timvisee/send) NodeJS version + Minio as storage backend,在此致谢!

我们使用 NVM 来安装 Node.js,使用 pm2 来运行和管理 send 服务。

首先安装运行环境,安装 NVM:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

安装 Node.js,Send 推荐用 Node.js 16,可是现在 Node.js 16 已经停止支持了,我们安装 20.x,接下来会遇到一个小问题,到时再说。

nvm install 20

安装 pm2:

npm install pm2 -g
pm2 install pm2-logrotate

设置 pm2 开机自启动:

pm2 startup

运行上面命令后,pm2 会给出一串代码,运行代码即可设置 pm2 开机自启:

[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/home/coke/.nvm/versions/node/v20.11.0/bin /home/coke/.nvm/versions/node/v20.11.0/lib/node_modules/pm2/bin/pm2 startup systemd -u coke --hp /home/coke

经过上面步骤,运行环境就安装好了,接下来下载 Send 代码并安装依赖

安装 git

sudo dnf install git -y

下载 Send 源码,注意,具体下载目录根据自己的选择来定。

git clone https://github.com/timvisee/send.git && cd send

安装依赖并构建

npm install
npm run build

然后在这里就出错了

> [email protected] build
> npm run clean && webpack


> [email protected] clean
> rimraf dist

mode: production
node:internal/crypto/hash:68
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^
Error: error:0308010C:digital envelope routines::unsupported
     中间大段错误提示省略。。。
     。。。。。。。。。。。。
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v20.11.0

上面提到 Node.js 版本太新的问题,这里是由于加密算法支持有问题,暂且使用 export NODE_OPTIONS=--openssl-legacy-provider 绕过,添加这个变量后再次运行即可。

最后,设置 Send 启动参数并使用 pm2 启动 Send 服务,注意我这里没有使用 redis,也没有使用 Amazon S3,就是简单的使用自己的服务器。

BASE_URL=https://send.coke.im DETECT_BASE_URL=true FILE_DIR=/home/coke/www/sendstorage pm2 start npm --name "Send" --update-env -- run prod

这里遇到一个问题,如果把上面的命令以反斜杠换行来写,貌似不行,send 并没有获取到这些参数,可能我的服务器因素,和教程有差别。

然后 pm2 save 来保存当前进程。

最后,配置 nginx 来代理请求到 Send 服务。这里的代码我是直接贴的 ditatompel Insights 的,根据自己的具体情况稍作修改即可。

server {
  listen 80;
  server_name send.example.com;
  root /var/www/nginx/default;
  location /.well-known/acme-challenge/ { allow all; }
  location / { return 301 https://$host$request_uri; }
}

server {
  listen 443 ssl http2;
  server_name send.example.com;

  # put your SSL confs here
  ssl_certificate     /path/to/ssl/fullchain.pem;
  ssl_certificate_key /path/to/ssl/privkey.pem;

  root /var/www/nginx/default;

  sendfile             on;
  client_max_body_size 3000m;

  location / {
    try_files $uri @proxysend;
  }

  location @proxysend {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Proxy "";
    proxy_pass_header Server;

    proxy_pass http://127.0.0.1:1443;
    proxy_buffering on;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    tcp_nodelay on;
  }

  location /api {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Proxy "";

    proxy_pass http://127.0.0.1:1443;
    proxy_buffering off;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    tcp_nodelay on;
  }
}

配置好 nginx server 后重新加载一下 nginx 配置,然后打开浏览器访问网址就可以打开 Send 了。