Fediverse Custom Domain with Nginx

I run a gotosocial instance since last year and wrote about it. The domain of the instance is fedi.cress.space, but I want @cress.space instead of @fedi.cress.space as domain for a user account. To get this a few redirects are needed. Jacobian wrote about this for Cloudflare Pages. For me the cress.space domain is already setup with nginx, so I wanted a solution that works with nginx.

The redirects needed in nginx (as an example for cress.space -> fedi.cress.space):

# webfinger
location /.well-known/webfinger {
  rewrite ^.*$ https://fedi.cress.space/.well-known/webfinger permanent;

location /.well-known/host-meta {
  rewrite ^.*$ https://fedi.cress.space/.well-known/host-meta permanent;

location /.well-known/nodeinfo {
  rewrite ^.*$ https://fedi.cress.space/.well-known/nodeinfo permanent;

The other change is in the gotosocial config (my change). I did this a while back on an empty gotosocial instance, so I don't know what happens if this is changed on an exsiting gotosocial database. For my setup both urls still work (the fedi.cress.space one and the cress.space one that is redirected), so I would assume changing it later works.