ミーハーなので、流行りの Mastodon サーバーを立ててみました。
https://mastodon.toycode.com/mastodon.toycode.com
基本的には、以前から自分の勉強用に借りている VPS に docker と docker-compose を入れて設定しただけです。
sslは、自宅サーバー用に *.toycode.com の ワイルド−カード ssl 証明書を取得していたのでそれを使いました。
また、メールサーバーは、契約していたけどあまり使っていなかった、さくらのメールボックスを使うことにしました。
具体的には、git clone しローカルにブランチを切った後、 nginx というディレクトリを作って、サーバー証明書と documentation/Production-guide.md at master · tootsuite/documentation を元に以下のように書き換え
--- default.conf.orig 2017-04-16 19:55:26.488591836 +0900
+++ default.conf 2017-04-16 13:19:25.319053418 +0900
@@ -6,14 +6,14 @@
server {
listen 80;
listen [::]:80;
- server_name example.com;
+ server_name mastodon.toycode.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
- server_name example.com;
+ server_name mastodon.toycode.com;
ssl_protocols TLSv1.2;
ssl_ciphers EECDH+AESGCM:EECDH+AES;
@@ -21,8 +21,8 @@
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;
+ ssl_certificate /etc/nginx/server.crt;
+ ssl_certificate_key /etc/nginx/server.key;
keepalive_timeout 70;
sendfile on;
@@ -53,7 +53,7 @@
proxy_set_header Proxy "";
proxy_pass_header Server;
- proxy_pass http://127.0.0.1:3000;
+ proxy_pass http://web:3000;
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;
@@ -70,7 +70,7 @@
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Proxy "";
- proxy_pass http://localhost:4000;
+ proxy_pass http://streaming:4000;
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;
@@ -82,3 +82,4 @@
error_page 500 501 502 503 504 /500.html;
}
+
Dockerfile を作り
#
FROM nginx:alpine
MAINTAINER Hiroshi Okada <okadahiroshi@miobox.jp>
COPY server.crt server.key /etc/nginx/
COPY default.conf /etc/nginx/conf.d/
EXPOSE 443 80
元の docker-compose.yml を以下のように書き換えて
version: '2'
services:
nginx:
build: ./nginx
image: okadahiroshi/nginx
depends_on:
- web
ports:
- "80:80"
- "443:443"
db:
restart: always
image: postgres:alpine
### Uncomment to enable DB persistance
volumes:
- ./postgres:/var/lib/postgresql/data
redis:
restart: always
image: redis:alpine
### Uncomment to enable REDIS persistance
volumes:
- ./redis:/data
web:
restart: always
build: .
image: gargron/mastodon
env_file: .env.production
command: bundle exec rails s -p 3000 -b '0.0.0.0'
depends_on:
- db
- redis
volumes:
- ./public/assets:/mastodon/public/assets
- ./public/system:/mastodon/public/system
streaming:
restart: always
build: .
image: gargron/mastodon
env_file: .env.production
command: npm run start
depends_on:
- db
- redis
sidekiq:
restart: always
build: .
image: gargron/mastodon
env_file: .env.production
command: bundle exec sidekiq -q default -q mailers -q pull -q push
depends_on:
- db
- redis
volumes:
- ./public/system:/mastodon/public/system
残りの作業は、 https://github.com/tootsuite/mastodon#running-with-docker-and-docker-compose の通りに作業しました。
あまりむずかしい作業ではありませんでしたが、 VPS が海外サーバーで、さくらのメールに国外IPアドレスフィルタが設定してあったので、
最初メール認証がうまくいなかくて焦りました。
なお、立ち上げたサーバーはしばらく(最低一年程度)は運用するつもりです。今は自由にアカウントを作れる状態にしていますので自由にアカウントを作っていただいて OK ですが、
負荷が多いようだったら、新規のアカウントの作成はできないようにするつもりです。(spam 行為でないかぎり作成済みのアカウントを故意に消すことはないと思います。)