用Mastodon搭建自己的Twitter
简介
Mastodon是一款‘去中心化’的开源社交软件,类似Twitter和新浪微博可以建立独立节点,也可以跨节点交流
机器环境
CentOS7Docker 18.06.1-ceDocker-compose 1.22GitNginx
下载项目代码
cd /home/
git clonelive
cd live
chown -R 991:991 public
编辑 docker-compose.yml
vi docker-compose.yml
# 去掉redis和postgresql的持久化的注释,使其可以持久化数据
拉取镜像
docker pull tootsuite/mastodon
配置域名/数据库/邮件系统/管理员账户
cp .env.production.sample .env.production
docker-compose run --rm web bundle exec rake mastodon:setup
# domain:填自己的域名,这里是192.168.88.104
# 将生成的配置信息填入.env.production里面的对应位置
vi .env.production
REDIS_HOST=redis
REDIS_PORT=6379
DB_HOST=db
DB_USER=postgres
DB_NAME=postgres
DB_PASS=
DB_PORT=5432
LOCAL_DOMAIN=192.168.172.50
SECRET_KEY_BASE=3d83e67ad3b2b84f54bb474ab969c6b4abc2411fc4403b33d69d4f8dace4dc1d3e2b4fb72ea2e5080e7221cc40f4ce28ceeb4de18cccfdf1c
OTP_SECRET=e7a0be8050c17d5410fbbe72a1e53d990c472c68d63ae11f4cc5e3cb7f8dc5c6a7d3ee6a74b41a11fd44ef114b171ccd6df5d2ec29b930
VAPID_PRIVATE_KEY=vUHcS8EL1BnykhW8QJiH8rvXALGKL_HlxJaCtDEx3DI=
VAPID_PUBLIC_KEY=BCZ7mKdUEtVkz1xFGxLjhSAOEOS-Hy0yOALGuD9LfwKwX6myXNpmTabgPTbRMFO8-6DBXFGi5GGkMFar9n1Aw=
SMTP_SERVER=smtp..com
SMTP_PORT=587
SMTP_LOGIN=xxxxxxx
SMTP_PASSWORD=xxxxxxxx
配置Nginx
vi /etc/nginx/conf.d/mysite.conf只需修改root为代码的目录即可,其它地方都不用改map $http_upgrade $connection_upgrade {
default upgrade;
close;
}
server {
listen 80;
listen [::]:80;
server_name example.com;
root /home/live/public;
# Useful for Lets Encrypt
location /.well-known/acme-challenge/ { allow all; }
location / { return 301 ; }
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
keepalive_timeout70;
sendfile on;
client_max_body_size 80m;
root /home/live/public;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
add_header Strict-Transport-Security "max-age=";
location / {
try_files $uri @proxy;
}
location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) {
add_header Cache-Control "public, max-age=, immutable";
try_files $uri @proxy;
}
location /sw.js {
add_header Cache-Control "public, max-age=0";
try_files $uri @proxy;
}
location @proxy {
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 https;
proxy_set_header Proxy "";
proxy_pass_header Server;
proxy_pass :3000;
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;
}
location /api/v1/streaming {
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 https;
proxy_set_header Proxy "";
proxy_pass :4000;
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;
}
error_page 500 501 502 503 504 /500.html;
}启动Nginx:nginx-c/etc/nginx/nginx.conf
启动Mastodon
cd /home/live
docker-compose up -d启动后访问:https://192.168.88.104 (注意这里为之前设置的域名)
常见问题
不能上传图片:必须保证/live/public/system的所属组是991chown -R 991:991 /home/live/public/system备份数据库docker-compose exec -T db pg_dump -U postgres postgres > backup.sql 备份上传的文件备份/home/live/public/system文件夹内容就可以了
效果预览