Object storage provider for Mastodon instance

We have ways to optimize performance. Please have a look at How to Hod Rod File Transfer Performance on Storj DCS - Storj DCS Docs


You also may configure nginx to be a cache proxy too, something like:

proxy_cache_path /tmp/nginx_mastodon_media levels=1:2 keys_zone=mastodon_media:100m max_size=1g inactive=24h;

server {
    listen 80;
    listen [::]:80;
    server_name media.your-site.tld;
    return 301 https://media.your-site.tld$request_uri;

    access_log /dev/null;
    error_log /dev/null;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name media.your-site.tld;

    access_log /var/log/nginx/mastodon-media-access.log;
    error_log /var/log/nginx/mastodon-media-error.log;

    # Add your certificate and HTTPS stuff here

    location /media/ {
        proxy_cache mastodon_media;
        proxy_cache_revalidate on;
        proxy_buffering on;
        proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
        proxy_cache_background_update on;
        proxy_cache_lock on;
        proxy_cache_valid 1d;
        proxy_cache_valid 404 1h;
        proxy_ignore_headers Cache-Control;
        add_header X-Cached $upstream_cache_status;
        proxy_pass http://bucket-domain.tld/media/;

You likely will need to configure CORS too.

We’ll be happy if we can get it together at all. Then we’ll look at optimization options. We haven’t gotten close to linking yet, just separately. He’s off the job again today, so we’ll try up again to see if we get anywhere. :thinking:

That mostly looks at optimizing larger transfers. I don’t think there is a lot you can do about time to first byte other than caching.

Hi Alexey, thanks for your reply that also pushed life back into this thread. Seems that the interest of running Mastodon instances is generally high. I was not able to perform any further testing yet due to high load at work but will check the gateaway and/or proxy solutions mentioned in the other replies.


We sat on it all afternoon yesterday and nothing. I have to admit that if I were to set something like this, without a manual, no chance of setting something like this up myself at all. I’m just an average server user, my specialty is 3D graphics and game development, but so I’m trying to help him with my experience.

So, I’m glad he made time for me again yesterday, and we tried something out.

Last time we said that the first option of direct linking doesn’t work natively. So, we tried the second part. We set up the uplink and managed to make a bridge, it worked properly, although somehow we didn’t understand why the access log said it wasn’t right for something when I was giving it all the permissions when generating the data, but then again that’s probably not that important because the uplink worked anyway. The problem was to combine this together in any way. Whatever data we tried to slip Mastodon, nothing. With http, https, private, public, everything we could think of to send it to local and then send it over the uplink, but just no. The uplink from our server to StorJ works, but that’s it, we can’t get any further. Tried maybe 4 different ways to somehow slip it in, but absolutely every time we encountered an issue. In all cases, it was the error message I mentioned here last time. We also played around with the domain, I set the bucket as a static website, we connected to the bucket again, but that was the end of it. We couldn’t manage to combine the two together again. I’m posting below the setup we worked with… We are really running out of options. I’m starting to slightly doubt that we’ll even be able to do this until someone does a tutorial because he himself told me he doesn’t know what else he could do differently.

oot@ns102719:~# uplink share --dns gateway.darksheep.social sj://mastodon --not-after=none
Sharing access to satellite 12L9ZFwhzVpuEKMUNUqkaTLGzwY9G24tbiigLiXpmZWKwmcNDDs@eu1.storj.io:7777
=========== ACCESS RESTRICTIONS ==========================================================
Download  : Allowed
Upload    : Disallowed
Lists     : Allowed
Deletes   : Disallowed
NotBefore : No restriction
NotAfter  : No restriction
Paths     : sj://mastodon/ (entire bucket)
Access    : code here
========== CREDENTIALS ===================================================================
Access Key ID: code here
Secret Key   : code here
Endpoint     : https://gateway.storjshare.io/
Public Access:  true
=========== DNS INFO =====================================================================
Remember to update the $ORIGIN with your domain name. You may also change the $TTL.
$ORIGIN example.com.
$TTL    3600
gateway.darksheep.social        IN      CNAME   link.storjshare.io.
txt-gateway.darksheep.social    IN      TXT     storj-root:mastodon
txt-gateway.darksheep.social    IN      TXT     storj-access:juqca3y2swq5scxd2ns4a4ydwdwa

Our test transfer was working. But only without Mastodon.


Did you specify the S3_ENDPOINT?


Perhaps S3_HOSTNAME should be


See also the lab with Pixelfed (for mastodon): How to set up Pixelfed on Ubuntu 22.04 connected to Storj DCS

1 Like

I think we tried that option as well, but when he has some time again, we’ll try again.

I watched the video, nice. Too bad they didn’t show it from Mastodon’s perspective as well, because it’s very similar. Whether it can be replicated on Mastodon, we’ll see. :pray:t2:

Anyway, if anyone manages to get it going meanwhile, I’d be really incredibly grateful if you’d share your experiences here on how you managed to sort it out. I believe there are many times more experienced programmers and administrators than me. Thank you.

but isnt ./uplink share --url --disallow-lists --not-after=none sj://bucketname creating a public accessable bucket?

Hey friends! I finally sat down today to figure out how to set up Mastodon with Storj. I tested the following instructions with Mastodon 4.0.2.

The summary is it works with the following config! It appears the missing trick from prior attempts is the S3_ALIAS_HOST field.


Okay, so the things you need here are:

  • A Storj bucket
  • Gateway credentials (access key and secret key)
  • Linksharing credentials for public access

Because of the linksharing credentials bit, the easiest way to generate all of the things you need is through our uplink CLI.

Assuming you have an uplink CLI set up (so that ls, mb, cp, etc work), the following should work for you:

To make a bucket, you can choose the bucketname, like mastodon, and do

uplink mb sj://mastodon

I’m going to keep calling it BUCKET for subsequent steps though.

To generate the GATEWAYKEY and GATEWAYSECRET, run

uplink share --readonly=false --register sj://BUCKET

This will make an access key and an access secret.

Finally, Storj doesn’t have the same sort of concept of public buckets that S3 has. We support public access, but it’s able to be more fine-grained than at the bucket level. So, we’re going to tell Mastodon about it with the S3_ALIAS_HOST setting, which seems to support path prefixes crammed in there as well.

To generate LINKSHARINGKEY you can do

uplink share --url --readonly --disallow-lists --not-after=none sj://BUCKET

You’ll get a URL, but the URL is not quite right. It will be of the form https://link.storjshare.io/s/LINKSHARINGKEY/BUCKET/, but the Mastodon S3_ALIAS_HOST should be link.storjshare.io/raw/LINKSHARINGKEY/BUCKET. Note the lack of https://, the swap of /s/ for /raw/, and the lack of trailing slash.

Once you have these things, you should be able to plop this configuration in to your Mastodon’s .env.production configuration and you should be all set to “boost” some media “toots”.


If you’re doing the rake mastodon:setup wizard, choosing Minio as your object storage provider and telling it you do want to access the uploaded files from your own domain should allow you to set the same settings in the setup wizard.

Of course, these instructions mean all your media will be served from link.storjshare.io, and maybe you don’t like that. You can always follow our instructions for sharing a bucket via DNS settings for your own domain name. If you do that, you’d replace S3_ALIAS_HOST with your domain name backed by Storj.

If you want a video walkthrough, while it’s not for Mastodon, the same problems are solved for Pixelfed in this Webinar: How to set up Pixelfed on Ubuntu 22.04 connected to Storj DCS - YouTube. Note that in the video, I stumbled over the gateway registration command, which should have been uplink share --readonly=false --register sj://pixelfed. We’re working to make that more intuitive.


As many flee Twitter currently looking for alternatives, this might be nice blog posting.


Thanks man, you’re a legend! I’ll have to check it out after work. :clap:t2:


the missing S3_ALIAS_HOST= was the issue in my configuration. Thanks to your guide i got it working now! Thanks a lot


Before I figured out the S3_ALIAS_HOST thing, I did write this blog post yesterday: Will Twitter’s Downfall Give Rise to the Decentralized Cloud?.

I agree with you we should do a followup post, but that said, folks in this thread should definitely check out the last paragraph in yesterday’s blog post:

if you’re operating Mastodon, Pixelfed, Peertube, Funkwhale, or another federated platform and need affordable object storage, you can sign up today and get a free 150GB of storage on Storj! We’ll also give up to 1 TB-month of storage and 1 TB of egress free if you speak to us to give us your feedback at fedi@storj.io!


Thanks for the confirmation this works by the way!

If it’s interesting, I added this setup to the Mastodon wizard in this pull request: Add Storj DCS to cloud object storage options by jtolio · Pull Request #21929 · mastodon/mastodon · GitHub


We’ve added docs here: Mastodon and Pixelfed - Storj DCS Docs


I’d like to thank you again. I can confirm everything is running as it should.

But I would like to raise two issues here that we have been thinking about. How does the uplink actually work? My understanding is that Mastodon communicates with the local folder on the VPS and what the uplink does is that it mirrors the files from that folder to StorJ if I’m not mistaken. But then that would mean that over time I would need the same amount of space on the VPS as well, since it was just a mirror. My idea is to not have to buy a large disk for the VPS, since those attachments will only be kept on StorJ. So, not sure if it can be configured that way, which is why I prefer to ask for reassurance.

The second question is. I’ve done tests with a working portal already, and it’s a pity that if a user uploads something and then decides to delete it, for example, it disappears from the tmp on the VPS, but it still stays on StorJ in the bucket, which is a pity that it doesn’t get deleted afterwards, freeing up space. I’m thinking that if an instance runs for maybe a couple of years, deleted user stuff that no longer points anywhere would make up a pretty large percentage unnecessarily. And I can’t think of a way to then sort it away from the chaos of folders manually. Does anyone have a tip on how this could be addressed as well? :thinking:

After you switching your storage to Storj it should not store anything locally (maybe only cache).
You may also run periodic cleanup jobs: Setting up your new instance - Mastodon documentation