Skip to content
Cloudflare Docs

Mastodon

Last reviewed: over 2 years ago

Mastodon is a popular fediverse software. This guide will explain how to configure R2 to be the object storage for a self hosted Mastodon instance, for either a new instance or an existing instance.

Set up a new instance

You can set up a self hosted Mastodon instance in multiple ways. Refer to the official documentation for more details. When you reach the Configuring your environment step in the Mastodon documentation after installation, refer to the procedures below for the next steps.

1. Determine the hostname to access files

Different from the default hostname of your Mastodon instance, object storage for files requires a unique hostname. As an example, if you set up your Mastodon's hostname to be mastodon.example.com, you can use mastodon-files.example.com or files.example.com for accessing files. This means that when visiting your instance on mastodon.example.com, whenever there are media attached to a post such as an image or a video, the file will be served under the hostname determined at this step, such as mastodon-files.example.com.

2. Create and set up an R2 bucket

  1. In the Cloudflare dashboard, go to the R2 object storage page.

    Go to Overview
  2. Select Create bucket.

  3. Enter your bucket name and then select Create bucket. This name is internal when setting up your Mastodon instance and is not publicly accessible.

  4. Once the bucket is created, navigate to the Settings tab of this bucket and copy the value of S3 API.

  5. From the Settings tab, select Connect Domain and enter the hostname from step 1.

  6. Navigate back to the R2's overview page and select Manage R2 API Tokens.

  7. Select Create API token.

  8. Name your token Mastodon by selecting the pencil icon next to the API name and grant it the Edit permission. Select Create API Token to finalize token creation.

  9. Copy the values of Access Key ID and Secret Access Key.

3. Configure R2 for Mastodon

While configuring your Mastodon instance based on the official configuration file, replace the File storage section with the following details.