This page looks best with JavaScript enabled

Mastodon on Unraid

 ·  ☕ 5 min read

Installing Mastodon on Unraid

I recently discovered Mastodon and wanted to give it a try but couldn’t find any guides on the internet that went over how to install it on Unraid. After a bit of hair pulling I managed to figure it out. So without further ado, here is how I did it.

mastodon.png

 
 

Get the necessary containers

Go to docker settings in Unraid and click “Add Container” we’re going to need three. I’ve linked the three I used from dockerhub below. It’s important that you setup PostgreSQL and Redis before the Mastodon container.
 

 

Redis

This one is pretty simple as the only setting to enter here is the Redis Port. I’d recommend using the default of 6379.

  • Port: 6379

redissettings.png

 

PostgreSQL

Here we need to setup a few more settings, including a host path for the postgres data, the name of our database, a postgres user and password, and finally the port.

  • Host Path: /mnt/user/appdata/postgresql
  • DB_NAME: mastodon
  • DB_USER: mastodon
  • DB_PASS: MySuperSecretPassword
  • PORT: 5432

postgresql.png

 

Mastodon

Oh boy, there are a lot of settings for Mastodon. You’ll start out by leaving OTP_SECRET, SECRET_KEY_BASE, VAPID_PRIVATE_KEY, and VAPI_PUBLIC_KEY blank. We’ll fill them in later. For now, just fill in the following settings:

  • Web Port: 3000
  • Streaming Port: 4000
  • Mastodon Files: /mnt/user/appdata/mastodon
  • DB_HOST: The IP address or hostname of the docker container running PostgreSQL
  • DB_USER: The user you set in your docker container for PostgreSQL above.
  • DB_NAME: The database name you created for use with Mastodon in PostgreSQL.
  • DB_PASS: The password you set for the user in PostgreSQL above.
  • REDIS_HOST: The IP address or hostname of the docker container running Redis.
  • LOCAL_DOMAIN: The domain or subdomain you’ll be hosting Mastodon on. E.g. social.mydomain.com
  • SMTP_SERVER: Your smtp address. E.g. for gmail smtp.gmail.com
  • SMTP_PORT: SMTP Port E.g. 25
  • SMTP_LOGIN: The username to login to your mail server.
  • SMTP_PASSWORD: The password for the e-mail account
  • SMTP_FROM_ADDRESS: The e-mail address you’d like Mastodon to appear to send from.
     
     
    mastodonsettings.png

 
 

Configuring and Starting Mastodon

  1. Start your Redis and PostgreSQL containers if you haven’t already.
  2. Next, start Mastodon. At this point we don’t expect it to be accessible or working but we need to use the container to generate some secrets for the blank variables we created earlier.

If the Mastodon container won’t start make sure that the Redis and PostgreSQL containers are already started and configured properly.
{.is-info}

  1. Access the Mastodon console from Unraid by going to Docker > Left Clicking on the ‘Mastodon’ container and selecting ‘Console’
    mastadonconsole.png
  2. Run these commands to generate your secrets:
1
2
3
RAILS_ENV=production bin/bundle exec rake secret
RAILS_ENV=production bin/bundle exec rake secret
RAILS_ENV=production bin/bundle exec rake mastodon:webpush:generate_vapid_key

The rake secret command was ran twice on purpose above. The result should look something like this:

1
2
3
4
5
6
7
8
/mastodon # RAILS_ENV=production bin/bundle exec rake secret
ac73d9c8886924febaba4c02a482a09987d93ed02a6fa41b5c6c88d73c146bd36b7321f7faa67ffc2cb03ac98090ded145819a2ca3e44418fae7aeded41b15d8
/mastodon # RAILS_ENV=production bin/bundle exec rake secret
7285b4dcf3baa6b07bde6591dff97a7d80bb2194b7ef5d98de97bc6cd2021dac8f92d8070c532cd1e00aa8fceced0a99f524f7890b78896feabcb4df773d0b9a
/mastodon # RAILS_ENV=production bin/bundle exec rake mastodon:webpush:generate_vapid_key
VAPID_PRIVATE_KEY=tmVOQQonccsF4QhG1KIh-GIDfWf2BJtEEP9BI2TYq2I=
VAPID_PUBLIC_KEY=BJvnRRGaukgxT6tQ7ESAsY-nKqEzm-Ehrr8O-Z2Mq7NAJs7YiPHmrryZ-6mshgjMDhP5cpcs7iHeEoHXCvOfz5w=
/mastodon # 
  1. Copy the first rake secret, edit your Mastodon container, and enter that value for OTP_SECRET, use the second secret value for SECRET_KEY_BASE.
  2. Now, do the same for your VAPID_PRIVATE_KEY and VAPID_PUBLIC_KEY with the values produced from the generate_vapid_key command.
  3. At this point you should be able to restart the Mastodon container and access it at http://YOURIP:3000 (if you used the default port)

 
 

Stopping Redirection

If you use CloudFlare be warned that you may have to turn off the proxy setting for your instance to properly federate or to follow remote users.
{.is-warning}

At this point Mastodon should start and produce no errors in the docker console.

However, on my setup I found out it was redirecting me from http://xxx.xxx.xxx.xxx:3000/ to https://xxx.xxx.xxx.xxx without the port.

This is because Mastadon runs its own copy of Nginx that redirects non-SSL traffic to SSL without keeping the port. To fix this, I needed to put Mastadon behind my reverse proxy that had SSL enabled already so it wouldn’t try to redirect.

This is making my site available at https://social.fixflare.com

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name social.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
    #Change the XXX.XXX.XXX.XXX to the IP or hostname of the container running mastodon
        proxy_pass http://XXX.XXX.XXX.XXX:3000;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

 
 

Making yourself Admin

  1. Go ahead and access the Mastodon page (https://social.yourdomain.com) and sign up for a new account:
    mastadonsignup.png
  2. If you setup your e-mail settings properly this should send you a confirmation link to your e-mail address. Login to your e-mail and confirm the registration.
  3. Access the Mastodon console again by going to Unraid > Docker > Left Clicking on the ‘Mastodon’ container and selecting ‘Console’
  4. Grant yourself administrative access by running this command, replace ‘YourUser’ with the username you signed up with excluding the ‘@’
1
RAILS_ENV=production bin/tootctl accounts modify YourUser --role admin

 
 

Finishing Up

After logging in, navigate to preferences, administration, Site settings page. While there are no technical requirements for filling in this information, it is considered crucial for operating a server for humans.

Contact username: Your username so people know who owns the server
Business e-mail: An e-mail address so people locked out of their accounts, or people without accounts, can contact you
Instance description: Why did you start this server? Who is it for? What makes it different?
Custom extended information: You can put all sorts of information in here but a code of conduct is recommended

After you fill these in, simply hit “Save changes”.

You should now have a functional, working, Mastodon server running from Unraid. Now get Tooting!

If you’re looking to federate with some other servers at the start. Try adding a relay to https://relay.mastodon.host/

Share on

Michael
WRITTEN BY
Michael
IT Engineer