Do you see three dots everywhere on your Mastodon instance?
Is the console on your instance flodded with
WebSocket connection to 'wss://yourinstance.website/api/v1/streaming/?stream=public:local&access_token=blahblahblah' failed: Error during WebSocket handshake: Unexpected response code: 502
WELL FOR SOME REASON NONE OF THE MASTODON SETUP GUIDES TELL YOU HOW TO SET THIS UP EVEN THOUGH ITS SUPER EASY AND ITS OBNOXIOUS AF
You need to do two things:
- Generate a VAPID key
- Get your nginx to serve up /api/v1/streaming correctly
The VAPID key goes in your .env.production file in your mastodon root folder. Thankfully it's very nice and tells you how to generate the keys!
# Generate with `RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key` task (`docker-compose run --rm web rake mastodon:webpush:generate_vapid_key` if you use docker compose)
So yeah depending on if you're dockerized or not, run the appropriate command and fill out VAPID_PRIVATE_KEY and VAPID_PUBLIC_KEY, E Z C L A P
Now you have to set up your nginx. Have a block in said nginx configuration that looks like this as a location block probably after your / location block:
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://127.0.0.1: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;
}
Note that I used 127.0.0.1 instead of localhost because my server has some weird issues where it isnt translating localhost correctly with ipv6 and whatever, this just works.
Once you reload your nginx config and restart/rebuild your mastodon server, streaming should now work and your instance will run much more smoothly with toots coming in as they do! Yay!
Thank you!