Created
November 9, 2022 13:06
-
-
Save dwsmart/b9733545030cde7451f8688538b945ab to your computer and use it in GitHub Desktop.
nginx conf for redirecting .well-known for mastodon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 [email protected], [email protected] | |
#and so on all to one account, e.g, @[email protected] 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. [email protected] | |
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