Mastodon usernames different from the domain used for installation

Hugo GameiroMastodon, SysAdmin

By default when you install Mastodon on a domain, or subdomain, that will determine how the username of users on that Mastodon server will be. Example, if you install Mastodon on social.example.com a user on that server will be @myusername@social.example.com.

This can be changed and you can install Mastodon on social.example.com but have your username be @myusername@example.com or even @myusername@differentdomain.com but that requires a configuration change to the domain used for usernames.

For this example let’s assume you want to install Mastodon on social.example.com and have your usernames to end in example.com.

First you need to have a valid TLS/SSL certificate on example.com. Meaning that the domain should be accessible via https.

Second you need to create a response URL template response to when a webfinger query is made on https://example.com/.well-known/host-meta. The easiest is to just make a redirect. Any query made to https://example.com/.well-known/host-meta should redirect to https://social.example.com/.well-known/host-meta and append to the URL any parameters passed.

So, if a query is made to:
https://example.com/.well-known/host-meta?resource=acct:myusername@example.com
it should redirect to:
https://social.example.com/.well-known/host-meta?resource=acct:myusername@example.com

Now if on example.com you are using Nginx you can do something like:

location = /.well-known/host-meta {
return 301 https://social.example.com$request_uri;
}

If on example.com you are using Apache you can do something like:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/.well-known/host-meta(.)$ RewriteRule ^(.) http://social.example.com/.well-known/host-meta%1 [R=302,NC]

I have reports of people using a static XML file that have also worked but I am not sure what problems this might cause. Something like this should respond on https://example.com/.well-known/host-meta even when parameters exist in the URL:

<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
  <Link rel="lrdd" type="application/xrd+xml" template=“https://social.example.com/.well-known/webfinger?resource={uri}”/>
</XRD>

Finally in the Mastodon configuration (.env.production) you should set LOCAL_DOMAIN and WEB_DOMAIN values. Using the previous example:
LOCAL_DOMAIN=example.com
WEB_DOMAIN=social.example.com

If you are hosting with me, then this final step about the Mastodon configuration is not necessary. You just need to reply to the email you got when you first sign up requesting that change during the installation process.