This week I’ve been experimenting with getting a Mastodon instance up and running and the best way of doing this. One of the things I’ve wanted to do which very few instances seem to implement, is running the Mastodon instance on subdomain.domain.tld yet using name @ domain.tld for the usernames, that’s got to be possible right?
Yes it is!
If you edit the Mastodon env.production
file and use the following:
LOCAL_DOMAIN=domain.tld
WEB_DOMAIN=subdomain.domain.tld
We’ll also need to forward Mastodon traffic, from the domain.tld - to the subdomain, as other instances on the internet won’t know about the subdomain, so all their traffic will need redirecting. You can do this in Apache by using mod_rewrite, in the sites .conf
file place:
RewriteEngine on
RewriteRule ^/.well-known/host-meta(.*)$ https://subdomain.domain.tld/.well-known/host-meta$1 [L,R=301]
RewriteRule ^/.well-known/webfinger(.*)$ https://subdomain.domain.tld/.well-known/webfinger$1 [L,R=301]
That’ll redirect all the traffic to the right place. Using Nginx you should be able to do it by adding the below to the .conf
file:
location = /.well-known/host-meta {
return 301 https://subdomain.domain.tld$request_uri;
}
location = /.well-known/webfinger {
return 301 https://subdomain.domain.tld$request_uri;
}
Webfinger seems to be used for new versions of Mastodon - however I’ve also forwarded host-meta in case old versions out there are still using it. I’ve not tested this on an instance that is already running - I would assume that existing accounts will retain their original usernames, so I’d only recommend on a new instance. Manually editing the existing usernames will likely break interactions with all other instances, breaking follows etc.