Making yourself discoverable in the Fediverse on your own domain

Inspired by this blog post by Maarten Balliauw, I also wanted to make my Mastodon account discoverable as in the Fediverse, although my user is

Maarten's idea is neat and simple: Download the webfinger file for your user from your actual host, and serve the same webfinger content from your own website.

There's a couple of things I thought could be improved, though:

I decided to try and achieve the same, purely by adding a few lines to my nginx configuration. I first tried using location and proxy_pass, but wasn't able to get it to work with the query string part of the webfinger URL. So I tried with an if and a redirect in the location instead, and I'm happy to see that it actually works.

In only 5 lines of nginx configuration, I'm able to make myself discoverable in the Fediverse by searching for my e-mail address:

location /.well-known/webfinger {
  if ($query_string = "") {
    return 301;

In my case, it's important that this is added to the configuration for the domain, not the domain, which is where I'm serving this blog from. But apart from that, it seems to be just working. Yay!