Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nginx conf for redirecting .well-known for mastodon
# before server {} block
# if you're not mapping $request_path already, you'll need to this next block
map $request_uri $request_path {
~(?<captured_path>[^?]*) $captured_path;
}
map $arg_resource $valid_mastodon {
# If you want any account at your domain to resolve to just one mastodon account, i.e bob@tamethebots.com, mary@tamethebots.com
#and so on all to one account, e.g, @dwsmart@seocommunity.social leave this next line uncommented
default 1;
# If you want limit the accounts to specific ones, comment out the above default 1; line and uncomment the following lines,
# replacing the accounts with your own, the following format:
# acct%3Ausername%40server 1;
# (it needs to be url encoded) %3A replaces the :, %40 replaces the @,
# so acct:dwsmart%40tamethebots.com becomes acct%3Adwsmart%40tamethebots.com
# add as many as you like, one per line after the default 0; line
# default 0;
# 'acct%3Adwsmart%40tamethebots.com' 1;
# 'acct%3Adave%40tamethebots.com' 1;
}
server {
#... other config
location ~ ^/.well-known/(host-meta|webfinger|nodeinfo) {
if ( $valid_mastodon = 1) {
# replace your details!
# YOUR_SERVER_INCLUDING_PROTOCOL full server, no trailing slash, e.g. https://seocommunity.social
# YOUR_HANDLE_WITH_SERVER, in format username@server, e.g. dwsmart@seocommunity.social
return 302 YOUR_SERVER_INCLUDING_PROTOCOL$request_path?resource=acct:YOUR_HANDLE_WITH_SERVER;
}
if ( $valid_mastodon = 0 ) {
# Mastodon account not in allowed list so return 404
return 404;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment