How to redirect webfinger to subdomain

1. The problem I’m having:

Hello Caddy community, I’m trying to understand how to do something in caddy, please bear with me, I’m a beginner in every tool and technology being used and doing this as my first learning project.

I have set a example.com to host multiple services for me and my friends, this far I have a photo album management service running on album.example.com and a cloud storage service running on cloud.example.com.

Now I want to run an akkoma (a pleroma/mastodon fork) server and web client on akkoma.example.com. The problem is that if I host my akkoma instance on a subdomain, my users will be @user@akkoma.example.com. If I want them to be @user@example.com, I need to change some configurations, one of them being in caddy. I have the following example code for nginx:

location = /.well-known/host-meta {
       return 301 https://akkoma.example.org$request_uri;
}

And I’m having trouble understanding how to implement this on caddy. I’ve searched both the web in general and this forum specifically, as well as read the caddy documentation. I haven’t tried it yet but I think the correct implementation would be:

example.com/.well-known/host-meta {
       redirect akkoma.example.com{uri}
}

akkoma.example.com {
       reverse_proxy localhost:8080
}

2. Error messages and/or full log output:

3. Caddy version:

v2.7.6

4. How I installed and ran Caddy:

5. Links to relevant resources:

https://mikihau.github.io/posts/self-hosting-akkoma/
https://docs.akkoma.dev/stable/configuration/how_to_serve_another_domain_for_webfinger/

Using paths in the site address is deprecated. You should use path matchers inside your site.

Something like this:

example.com {
	redir /.well-known/host-meta https://akkoma.example.com{uri} permanent
}

This uses the redir directive, with an inline path matcher.

Keep in mind that Caddy isn’t configured to handle anything else for example.com with this config, you should probably serve something to the user, otherwise they’ll just get empty 200 status responses.

Hello Francis, thank you for the answer!
If I understood you correctly then I can do something like this:

example.com {
	redir /.well-known/host-meta https://akkoma.example.com{uri} permanent 
    file_server
}

To both have a page served at example.com and have akkoma working properly at akkoma.example.com. Is that correct? In any case I will try to set it up as you instructed and come back to either confirm that it works or to ask for further support if it doesn’t work.

Yep. You’ll probably need the root directive as well to tell file_server where to read files from.

I had some trouble getting akkoma to work properly, and when I managed to get it working it was running on my subdomain with users registering there too. So in the end I don’t know if this would have worked or not, but I hope it is useful for someone in the future. I’m gonna favorite this post so I can check it if or when I try doing this again. Once again thanks for the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.