概要
Apache httpdでMastodonを動かす設定をググると、大体↓みたいなのが出てくるが、これだとWebUI以外の一部のクライアントでストリーミングが使えない。
# ProxyPass以外は省略
ProxyPass /api/v1/streaming/ ws://localhost:4000/
ProxyPassReverse /api/v1/streaming/ ws://localhost:4000/
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
Mastodon公式の旧ドキュメント
https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Alternatives.md
でもこうなってしまっている。
↓のようにすると正常に動作する。
# ProxyPass以外は省略
<LocationMatch "^/api/v1/streaming/?$">
ProxyPass ws://localhost:4000/api/v1/streaming
ProxyPassReverse ws://localhost:4000/api/v1/streaming
</LocationMatch>
ProxyPass /api/v1/streaming/ http://localhost:4000/api/v1/streaming/
ProxyPassReverse /api/v1/streaming/ http://localhost:4000/api/v1/streaming/
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
何が起きるの?
- WebSocket( /api/v1/streaming?... )を使おうとすると、リダイレクトループが起きて死ぬ
- なおWebUIはどういうわけか /api/v1/streaming/?... ("?"の直前に"/"がある)というURLを使っていて、こちらは正常に動作する
- Server-sent events ( /api/v1/streaming/public など)は全く動作しない
原因っぽいの
現象が2つなので原因も2つに分けて書く。
WebSocketが死ぬ方
/api/v1/streaming?... へのアクセスが mastodon-web (http://localhost:3000/api/v1/streaming?...) に飛ばされてしまうのが原因。
そしてこれが HTTP 301(Moved Permanently)で全く同じURLにリダイレクトしてしまいループして死ぬ。
これはWebSocket接続で mastodon-streaming (ws://localhost:4000/... ) に飛ばす必要がある。
さらに /api/v1/streaming/?... ("/"がついている)も同様にWebSocket接続で mastodon-streaming に飛ばす必要がある。
ちなみにWebSocket接続時は、mastodon-streaming がURL("?"より前の文字列)を無視するので、こんな風にしても問題なく動く(少なくともVer 2.8.4ではそうだった)。
<LocationMatch "^/api/v1/streaming/?$">
ProxyPass ws://localhost:4000/
ProxyPassReverse ws://localhost:4000/
</LocationMatch>
Server-sent eventsが使えない方
/api/v1/streaming/xxxx (publicなど) がWebSocket接続で mastodon-streaming (ws://localhost:4000/...) に飛ばされてしまうのが原因。
これは HTTP接続で mastodon-streaming (http://localhost:4000/...) に飛ばす必要がある。
さらに、mastodon-streamingに投げるURLには "/api/v1/streaming/" を残しておく必要がある。
にゃーん
Mastodon公式にもあるnginxの設定はもっとスマートだし、Apache httpdでももう少し綺麗に書けないかなとは思う。
にゃーん2
どういうわけかPawooからのトゥがまともに送られてこない不具合が発生したのでnginxに戻したorz