用Docker搭建Misskey去中心化社交平台

安装Docker

1
curl -fsSL https://get.docker.com | bash

由于新版docker自带compose,所以不用单独安装。

克隆项目

1
2
3
4
cd /opt
git clone -b master https://github.com/misskey-dev/misskey.git
cd misskey
git checkout master

修改配置文件

首先复制一份

1
2
cp .config/example.yml .config/default.yml
cp .config/docker_example.env .config/docker.env

编辑default.yml

1
vim .config/default.yml

其中url: https://example.tld/改为你的实例域名
dbhost改为docker-compose.yml里的services名,dbuserpass分别改为你的数据库名,用户,密码。
redishost改为docker-compose.yml里的services名。

编辑docker.env

1
vim .config/docker.env

这里的配置和default.yml保持一致

构建镜像和初始化

如果内存太小,建议直接选择已构建好的镜像

1
2
docker compose build
docker compose run --rm web pnpm run init

启动容器

1
docker compose up -d

配置Nginx反向代理

Misskey文档给了一份配置文件,根据自己需求改改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# For WebSocket
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=cache1:16m max_size=1g inactive=720m use_temp_path=off;

server {
listen 80;
listen [::]:80;
server_name example.tld;

# For SSL domain validation
root /var/www/html;
location /.well-known/acme-challenge/ { allow all; }
location /.well-known/pki-validation/ { allow all; }
location / { return 301 https://$server_name$request_uri; }
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.tld;

ssl_session_timeout 1d;
ssl_session_cache shared:ssl_session_cache:10m;
ssl_session_tickets off;

# To use Let's Encrypt certificate
ssl_certificate /etc/letsencrypt/live/example.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.tld/privkey.pem;

# To use Debian/Ubuntu's self-signed certificate (For testing or before issuing a certificate)
#ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
#ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;

# SSL protocol settings
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_stapling on;
ssl_stapling_verify on;

# Change to your upload limit
client_max_body_size 80m;

# Proxy to Node
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_redirect off;

# If it's behind another reverse proxy or CDN, remove the following.
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 https;

# For WebSocket
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

# Cache settings
proxy_cache cache1;
proxy_cache_lock on;
proxy_cache_use_stale updating;
proxy_force_ranges on;
add_header X-Cache $upstream_cache_status;
}
}

如果实例套了CDN,需要删掉55-58行

升级实例

在实例目录执行

1
2
3
4
5
6
7
git stash
git checkout master
git pull
git submodule update --init
git stash pop
sudo docker compose build
sudo docker compose stop && sudo docker compose up -d

用Docker搭建Misskey去中心化社交平台
https://blog.xzh.gs/2023/01/09/docker-misskey/
作者
XZH
发布于
2023年1月9日
更新于
2023年1月28日
许可协议