Skip to content

Instantly share code, notes, and snippets.

@dwsmart
Created November 9, 2022 13:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwsmart/b9733545030cde7451f8688538b945ab to your computer and use it in GitHub Desktop.
Save dwsmart/b9733545030cde7451f8688538b945ab to your computer and use it in GitHub Desktop.
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