关于 Mastodon 安装,官方安装文档已经说的很清楚了。 所以就不再赘述了,本文只讲一讲不一样的地方。

安装 Node.js、Yarn

没有什么改变,参考官方安装文档即可。

安装依赖

Debian 上部分包不同于 Ubuntu 需要有所改变。 另外,由于前端反代使用的 Caddy,所以没有安装 Nginx、certbot。

apt update
apt install -y \
ffmpeg  file  git-core g++ libpq-dev libxml2-dev libxslt1-dev \
protobuf-compiler pkg-config autoconf imagemagick nodejs yarn \
bison build-essential libssl-dev libyaml-dev libreadline-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \
libjemalloc-dev redis-server redis-tools postgresql \
postgresql-contrib protobuf-compiler libicu-dev libidn11-dev \
libprotobuf-dev libreadline-dev libpam0g-dev

安装 Ruby

参考官方安装文档

配置 PostgreSQL

大体参考官方安装文档

创建用户时,额外添加了密码。

CREATE USER mastodon WITH PASSWORD 'password' CREATEDB;

配置 Mastodon

参考官方安装文档

设置 Caddy

Caddyfile

example.com {
log / /var/log/caddy/mastodon.log "{combined}" {
  rotate_age 14
  rotate_compress
}

root /home/mastodon/live/public

gzip


tls [email protected]

header / {
  Strict-Transport-Security "max-age=31536000;"
  -Server
}
header /emoji Cache-Control "public, max-age=31536000, immutable"
header /packs Cache-Control "public, max-age=31536000, immutable"
header /system/accounts/avatars Cache-Control "public, max-age=31536000, immutable"
header /system/media_attachments/files Cache-Control "public, max-age=31536000, immutable"
header /sw.js Cache-Control "public, max-age=0"

rewrite {
  if {path} is /
  to /proxy{path}
}

rewrite {
  if {path} not_has /api/v1/streaming
  to {path} /proxy{path}
}

proxy /proxy localhost:3000 {
  without /proxy
  transparent
  websocket
}

proxy /api/v1/streaming localhost:4000 {
  transparent
  websocket
}

errors /var/log/caddy/mastodon_errors.log {
  500 500.html
  501 500.html
  502 500.html
  503 500.html
  504 500.html
  rotate_age 90
  rotate_compress
}
}

另外如果使用 systemd 启动 Caddy,请注意将 ProtectHome=true 改为 ProtectHome=false

设置 systemd 服务

参考官方安装文档