ということで、前回、前々回とmastodon を FreeBSD jail 上で動かす件について書いてきましたが これで最後(になる予定)
mastodon のインスタンスを、完全に内部だけで、外とも連携せずに使うのであれば、前回動かした状態でも大丈夫ですが、せっかくですので外部のインスタンスとの連携を考えます。
そのためには、外部に公開できるようなドメインが必要です。また、SSLも強く推奨されます。 以前はSSLのキーの取得には結構な金額がかかっていましたが、今は Let’s Encrypt を使えば無償で手に入れることができます。ただしこの鍵の有効期限は3か月ですが、鍵の取得と更新を自動的に行ってくれるスクリプトもありますので、それを使って取得と更新をするようにします。
まず最初はドメインの取得ですが、これはすでに持っていること前提に話を進めます。またDNSの設定もここでは説明しません。 これが分からない人はたぶんmastodon のインスタンスを立てようとは思わないでしょう。
ここでは便宜的に mstdn.mousou.org を使うことにします。各自適当に読み替えてください。
DNSの設定が適切に終わっているものとして、まずSSLのカギを取得しましょう。 mastodon_web のコンソールに接続。
つぎに nginx の設定です。 Production guide にサンプルがありますので、それをまるっと使って新規にファイルを作ります。また、ここで minio の設定と、サービスを休止するさいの設定を入れておきましょう。 /home/mastodon/live/maintenance.txt を作成すると 503 を返すようになるので、mastodon のメンテナンスやアップデートの際に、nginx を止めたり設定を変えたりしなくても自動でやってくれるようになります。
map $http_upgrade $connection_upgrade { default upgrade; ’’ close; }
server { listen 80;
listen [::]:80;
server_name mstdn.mousou.org;
Useful for Let’s Encrypt
location /.well-known/acme-challenge/ { allow all; } location / { return 301 https://$host$request_uri; } }
server { listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mstdn.mousou.org;
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 /usr/local/etc/letsencrypt/live/mstdn.mousou.org/fullchain.pem; ssl_certificate_key /usr/local/etc/letsencrypt/live/mstdn.mousou.org/privkey.pem; ssl_dhparam /usr/local/etc/ssl/dhparam.pem;
keepalive_timeout 70; sendfile on; client_max_body_size 0;
root /home/mastodon/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=31536000”; add_header Content-Security-Policy “style-src ‘self’ ‘unsafe-inline’; script-src ‘self’; object-src ‘self’; img-src data: https:; media-src data: https:; connect-src ‘self’ wss://mstdn.mousou.org; upgrade-insecure-requests”;
if ( -f “/home/mastodon/live/maintenance.txt” ) { set $maintenance true; }
location / { if ($maintenance = true) { return 503; } try_files $uri @proxy; }
location ~ ^/(assets|system/media_attachments/files|system/accounts/avatars) { add_header Cache-Control “public, max-age=31536000, immutable”; 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 http://mastodon_web: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 http://mastodon_web: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;
}
#mineo のための設定 location /mstdn.mousou.org { # minio で指定したバケット名を使う。 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 http://mastodon_minio:9000;
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; }
ここまで設定で来たら /usr/local/etc/nginx 以下にファイルをコピーして、今度は nginx.conf を修正しましょう。 httpディレクティブの中に、
これで公開する準備はできました。 あとは、
最後に、daily で回すcronを設定します。
3回で終わるはずだったのですが、あともう一回だけ続くんじゃよ。