How to enable Streaming for your Mastodon server if you use JWilder’s Nginx Proxy

A guest blog written by ChatGPT! After it helped me figure out how to get the config of nginx-proxy fixed; apparently it knows about it so it could give me detailed instructions on how to do it from the start!

I haven’t used ChatGPT to detail out blogs yet, but it seems like a nice way to turn information snippets into something more useful, because I can’t always be bothered to write a full blog post for something I can explain in two lines. So I think I’m gonna start doing that more.

Without further ado;

Enabling Streaming with jwilder’s nginx-proxy for Mastodon

When using jwilder’s nginx-proxy for containerized web applications like Mastodon, you might find that the streaming endpoint doesn’t work out-of-the-box. This is because the real-time streaming functionality of Mastodon requires WebSockets, and some additional configuration is needed to route these requests correctly.

Here’s a step-by-step guide to get it working:

  1. Identify the Streaming Service Endpoint: Mastodon separates its services, and one of them is the streaming service, typically running on port 4000. Ensure you have this service set up and running in a container.

  2. Custom Configuration for nginx-proxy: jwilder’s nginx-proxy allows for custom configuration snippets via the vhost.d directory. These configurations can be used to modify the behavior of Nginx for specific virtual hosts.

  3. Add the Custom Configuration:
    • Create a file with a name that matches the domain you’re configuring, appended with _location. For a Mastodon instance on mastodon.derg.nz, the file should be named mastodon.derg.nz_location.
    • Place the file in the vhost.d directory of your nginx-proxy setup.
    • Add the following content to the file:
    location /api/v1/streaming {
        proxy_pass http://streaming:4000; # "streaming" should match the name of your Mastodon streaming service container
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Proxy "";
        proxy_http_version 1.1;
    }
    

    Ensure the proxy_pass directive points to the name of your Mastodon streaming service container and the correct port (commonly 4000).

  4. Restart nginx-proxy: After adding the custom configuration, restart the nginx-proxy container to apply the changes.

  5. Test the Streaming Endpoint: You can now visit your Mastodon instance and test the real-time streaming functionality to ensure it’s working.

This setup ensures that the WebSockets requests for Mastodon’s real-time features are correctly proxied to the streaming service, ensuring a seamless user experience on your instance!

Updated: