LoginSignup
0
1

More than 3 years have passed since last update.

【Mastodon+Apache httpd】そのProxyPassではストリーミングが正常に動かない

Last updated at Posted at 2019-06-04

概要

Apache httpdでMastodonを動かす設定をググると、大体↓みたいなのが出てくるが、これだとWebUI以外の一部のクライアントでストリーミングが使えない。

mastodon-NG.conf
# 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
でもこうなってしまっている。

↓のようにすると正常に動作する。

mastodon-OK.conf
# 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ではそうだった)。

mastodon-OK2.conf
  <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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1